X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fassets%2Fplayer%2Futils.ts;h=81fe689514e057183b344fa75d7d1785378e1050;hb=b6a8cfc5714c93d0ecf6154e5d3a25b33b50b8cd;hp=0966027ace04e171d1832f9c39a93596dff821bf;hpb=c47106315ae3c403239cda29c49b4bba51ddccb2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index 0966027ac..81fe68951 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts @@ -4,6 +4,25 @@ function toTitleCase (str: string) { return str.charAt(0).toUpperCase() + str.slice(1) } +function isWebRTCDisabled () { + return !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false +} + +function isIOS () { + if (/iPad|iPhone|iPod/.test(navigator.platform)) { + return true + } + + // Detect iPad Desktop mode + return navigator.maxTouchPoints && + navigator.maxTouchPoints > 2 && + /MacIntel/.test(navigator.platform) +} + +function isSafari () { + return /^((?!chrome|android).)*safari/i.test(navigator.userAgent) +} + // https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts // Don't import all Angular stuff, just copy the code with shame const dictionaryBytes: Array<{max: number, type: string}> = [ @@ -23,18 +42,58 @@ function isMobile () { return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) } -function buildVideoLink (time?: number, url?: string) { - if (!url) url = window.location.origin + window.location.pathname.replace('/embed/', '/watch/') +function buildVideoLink (options: { + baseUrl?: string, + + startTime?: number, + stopTime?: number, - if (time) { - const timeInt = Math.floor(time) + subtitle?: string, - const params = new URLSearchParams(window.location.search) - params.set('start', secondsToTime(timeInt)) + loop?: boolean, + autoplay?: boolean, + muted?: boolean, - return url + '?' + params.toString() + // Embed options + title?: boolean, + warningTitle?: boolean, + controls?: boolean +} = {}) { + const { baseUrl } = options + + const url = baseUrl + ? baseUrl + : window.location.origin + window.location.pathname.replace('/embed/', '/watch/') + + const params = new URLSearchParams(window.location.search) + // Remove these unused parameters when we are on a playlist page + params.delete('videoId') + params.delete('resume') + + if (options.startTime) { + const startTimeInt = Math.floor(options.startTime) + params.set('start', secondsToTime(startTimeInt)) + } + + if (options.stopTime) { + const stopTimeInt = Math.floor(options.stopTime) + params.set('stop', secondsToTime(stopTimeInt)) } + if (options.subtitle) params.set('subtitle', options.subtitle) + + if (options.loop === true) params.set('loop', '1') + if (options.autoplay === true) params.set('autoplay', '1') + if (options.muted === true) params.set('muted', '1') + if (options.title === false) params.set('title', '0') + if (options.warningTitle === false) params.set('warningTitle', '0') + if (options.controls === false) params.set('controls', '0') + + let hasParams = false + params.forEach(() => hasParams = true) + + if (hasParams) return url + '?' + params.toString() + return url } @@ -81,7 +140,7 @@ function secondsToTime (seconds: number, full = false, symbol?: string) { function buildVideoEmbed (embedUrl: string) { return '' @@ -141,11 +200,14 @@ export { toTitleCase, timeToInt, secondsToTime, + isWebRTCDisabled, buildVideoLink, buildVideoEmbed, videoFileMaxByResolution, videoFileMinByResolution, copyToClipboard, isMobile, - bytes + bytes, + isIOS, + isSafari }