1 import { escapeHTML } from '@shared/core-utils/renderer'
2 import { VideoFile } from '@shared/models'
4 function toTitleCase (str: string) {
5 return str.charAt(0).toUpperCase() + str.slice(1)
8 function isWebRTCDisabled () {
9 return !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false
13 if (/iPad|iPhone|iPod/.test(navigator.platform)) {
17 // Detect iPad Desktop mode
18 return !!(navigator.maxTouchPoints &&
19 navigator.maxTouchPoints > 2 &&
20 navigator.platform.includes('MacIntel'))
23 function isSafari () {
24 return /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
27 // https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts
28 // Don't import all Angular stuff, just copy the code with shame
29 const dictionaryBytes: Array<{max: number, type: string}> = [
30 { max: 1024, type: 'B' },
31 { max: 1048576, type: 'KB' },
32 { max: 1073741824, type: 'MB' },
33 { max: 1.0995116e12, type: 'GB' }
35 function bytes (value: number) {
36 const format = dictionaryBytes.find(d => value < d.max) || dictionaryBytes[dictionaryBytes.length - 1]
37 const calc = Math.floor(value / (format.max / 1024)).toString()
39 return [ calc, format.type ]
42 function isMobile () {
43 return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent)
46 function buildVideoOrPlaylistEmbed (embedUrl: string, embedTitle: string) {
47 const title = escapeHTML(embedTitle)
49 return '<iframe width="560" height="315" ' +
50 'sandbox="allow-same-origin allow-scripts allow-popups" ' +
51 'title="' + title + '" ' +
52 'src="' + embedUrl + '" ' +
53 'frameborder="0" allowfullscreen>' +
57 function videoFileMaxByResolution (files: VideoFile[]) {
60 for (let i = 1; i < files.length; i++) {
62 if (max.resolution.id < file.resolution.id) max = file
68 function videoFileMinByResolution (files: VideoFile[]) {
71 for (let i = 1; i < files.length; i++) {
73 if (min.resolution.id > file.resolution.id) min = file
79 function getRtcConfig () {
83 urls: 'stun:stun.stunprotocol.org'
86 urls: 'stun:stun.framasoft.org'
92 // ---------------------------------------------------------------------------
99 buildVideoOrPlaylistEmbed,
100 videoFileMaxByResolution,
101 videoFileMinByResolution,