]>
Commit | Line | Data |
---|---|---|
4097c6d6 | 1 | import { escapeHTML } from '@shared/core-utils/renderer' |
15a7eafb | 2 | import { VideoFile } from '@shared/models' |
e945b184 | 3 | |
c6352f2c C |
4 | function toTitleCase (str: string) { |
5 | return str.charAt(0).toUpperCase() + str.slice(1) | |
6 | } | |
7 | ||
31b6ddf8 C |
8 | function isWebRTCDisabled () { |
9 | return !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false | |
10 | } | |
11 | ||
3e2bc4ea | 12 | function isIOS () { |
b6a8cfc5 C |
13 | if (/iPad|iPhone|iPod/.test(navigator.platform)) { |
14 | return true | |
15 | } | |
16 | ||
17 | // Detect iPad Desktop mode | |
b12ce2b8 | 18 | return !!(navigator.maxTouchPoints && |
b6a8cfc5 | 19 | navigator.maxTouchPoints > 2 && |
b12ce2b8 | 20 | /MacIntel/.test(navigator.platform)) |
3e2bc4ea C |
21 | } |
22 | ||
23 | function isSafari () { | |
24 | return /^((?!chrome|android).)*safari/i.test(navigator.userAgent) | |
25 | } | |
26 | ||
c6352f2c C |
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' } | |
34 | ] | |
c199c427 | 35 | function bytes (value: number) { |
c6352f2c C |
36 | const format = dictionaryBytes.find(d => value < d.max) || dictionaryBytes[dictionaryBytes.length - 1] |
37 | const calc = Math.floor(value / (format.max / 1024)).toString() | |
38 | ||
39 | return [ calc, format.type ] | |
40 | } | |
41 | ||
d1bd87e0 C |
42 | function isMobile () { |
43 | return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) | |
44 | } | |
45 | ||
4097c6d6 TP |
46 | function buildVideoOrPlaylistEmbed (embedUrl: string, embedTitle: string) { |
47 | const title = escapeHTML(embedTitle) | |
15a7eafb | 48 | |
960a11e8 | 49 | return '<iframe width="560" height="315" ' + |
f2aa2c3c | 50 | 'sandbox="allow-same-origin allow-scripts allow-popups" ' + |
4097c6d6 | 51 | 'title="' + title + '" ' + |
960a11e8 C |
52 | 'src="' + embedUrl + '" ' + |
53 | 'frameborder="0" allowfullscreen>' + | |
54 | '</iframe>' | |
55 | } | |
56 | ||
6cca7360 C |
57 | function videoFileMaxByResolution (files: VideoFile[]) { |
58 | let max = files[0] | |
59 | ||
60 | for (let i = 1; i < files.length; i++) { | |
61 | const file = files[i] | |
62 | if (max.resolution.id < file.resolution.id) max = file | |
63 | } | |
64 | ||
65 | return max | |
66 | } | |
67 | ||
68 | function videoFileMinByResolution (files: VideoFile[]) { | |
69 | let min = files[0] | |
70 | ||
71 | for (let i = 1; i < files.length; i++) { | |
72 | const file = files[i] | |
73 | if (min.resolution.id > file.resolution.id) min = file | |
74 | } | |
75 | ||
76 | return min | |
77 | } | |
78 | ||
09209296 C |
79 | function getRtcConfig () { |
80 | return { | |
81 | iceServers: [ | |
82 | { | |
83 | urls: 'stun:stun.stunprotocol.org' | |
84 | }, | |
85 | { | |
86 | urls: 'stun:stun.framasoft.org' | |
87 | } | |
88 | ] | |
89 | } | |
90 | } | |
91 | ||
7b3a99d5 C |
92 | // --------------------------------------------------------------------------- |
93 | ||
c6352f2c | 94 | export { |
09209296 | 95 | getRtcConfig, |
c6352f2c | 96 | toTitleCase, |
31b6ddf8 | 97 | isWebRTCDisabled, |
9162fdd3 | 98 | |
951b582f | 99 | buildVideoOrPlaylistEmbed, |
6cca7360 C |
100 | videoFileMaxByResolution, |
101 | videoFileMinByResolution, | |
d1bd87e0 | 102 | isMobile, |
3e2bc4ea C |
103 | bytes, |
104 | isIOS, | |
105 | isSafari | |
c6352f2c | 106 | } |