+import { VideoFile } from '../../../../shared/models/videos'
+
function toTitleCase (str: string) {
return str.charAt(0).toUpperCase() + str.slice(1)
}
return [ calc, format.type ]
}
-function getStoredVolume () {
- const value = getLocalStorage('volume')
- if (value !== null && value !== undefined) {
- const valueNumber = parseFloat(value)
- if (isNaN(valueNumber)) return undefined
+function isMobile () {
+ return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent)
+}
+
+function buildVideoLink (time?: number) {
+ let href = window.location.href.replace('/embed/', '/watch/')
+ if (time) {
+ const timeInt = Math.floor(time)
- return valueNumber
+ if (window.location.search) href += '&start=' + timeInt
+ else href += '?start=' + timeInt
}
- return undefined
+ return href
}
-function getStoredMute () {
- const value = getLocalStorage('mute')
- if (value !== null && value !== undefined) return value === 'true'
+function buildVideoEmbed (embedUrl: string) {
+ return '<iframe width="560" height="315" ' +
+ 'sandbox="allow-same-origin allow-scripts" ' +
+ 'src="' + embedUrl + '" ' +
+ 'frameborder="0" allowfullscreen>' +
+ '</iframe>'
+}
- return undefined
+function copyToClipboard (text: string) {
+ const el = document.createElement('textarea')
+ el.value = text
+ el.setAttribute('readonly', '')
+ el.style.position = 'absolute'
+ el.style.left = '-9999px'
+ document.body.appendChild(el)
+ el.select()
+ document.execCommand('copy')
+ document.body.removeChild(el)
}
-function getAverageBandwidth () {
- const value = getLocalStorage('average-bandwidth')
- if (value !== null && value !== undefined) {
- const valueNumber = parseInt(value, 10)
- if (isNaN(valueNumber)) return undefined
+function videoFileMaxByResolution (files: VideoFile[]) {
+ let max = files[0]
- return valueNumber
+ for (let i = 1; i < files.length; i++) {
+ const file = files[i]
+ if (max.resolution.id < file.resolution.id) max = file
}
- return undefined
+ return max
}
-function saveVolumeInStore (value: number) {
- return setLocalStorage('volume', value.toString())
-}
+function videoFileMinByResolution (files: VideoFile[]) {
+ let min = files[0]
-function saveMuteInStore (value: boolean) {
- return setLocalStorage('mute', value.toString())
-}
+ for (let i = 1; i < files.length; i++) {
+ const file = files[i]
+ if (min.resolution.id > file.resolution.id) min = file
+ }
-function saveAverageBandwidth (value: number) {
- return setLocalStorage('average-bandwidth', value.toString())
+ return min
}
-function isMobile () {
- return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent)
-}
+// ---------------------------------------------------------------------------
export {
toTitleCase,
- getStoredVolume,
- saveVolumeInStore,
- saveAverageBandwidth,
- getAverageBandwidth,
- saveMuteInStore,
- getStoredMute,
+ buildVideoLink,
+ buildVideoEmbed,
+ videoFileMaxByResolution,
+ videoFileMinByResolution,
+ copyToClipboard,
isMobile,
bytes
}
-
-// ---------------------------------------------------------------------------
-
-const KEY_PREFIX = 'peertube-videojs-'
-
-function getLocalStorage (key: string) {
- try {
- return localStorage.getItem(KEY_PREFIX + key)
- } catch {
- return undefined
- }
-}
-
-function setLocalStorage (key: string, value: string) {
- try {
- localStorage.setItem(KEY_PREFIX + key, value)
- } catch { /* empty */ }
-}