aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets/player/utils.ts')
-rw-r--r--client/src/assets/player/utils.ts43
1 files changed, 36 insertions, 7 deletions
diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts
index 8b9f34b99..366689962 100644
--- a/client/src/assets/player/utils.ts
+++ b/client/src/assets/player/utils.ts
@@ -4,6 +4,10 @@ function toTitleCase (str: string) {
4 return str.charAt(0).toUpperCase() + str.slice(1) 4 return str.charAt(0).toUpperCase() + str.slice(1)
5} 5}
6 6
7function isWebRTCDisabled () {
8 return !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false
9}
10
7// https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts 11// https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts
8// Don't import all Angular stuff, just copy the code with shame 12// Don't import all Angular stuff, just copy the code with shame
9const dictionaryBytes: Array<{max: number, type: string}> = [ 13const dictionaryBytes: Array<{max: number, type: string}> = [
@@ -42,7 +46,7 @@ function timeToInt (time: number | string) {
42 if (!time) return 0 46 if (!time) return 0
43 if (typeof time === 'number') return time 47 if (typeof time === 'number') return time
44 48
45 const reg = /^((\d+)h)?((\d+)m)?((\d+)s?)?$/ 49 const reg = /^((\d+)[h:])?((\d+)[m:])?((\d+)s?)?$/
46 const matches = time.match(reg) 50 const matches = time.match(reg)
47 51
48 if (!matches) return 0 52 if (!matches) return 0
@@ -54,18 +58,27 @@ function timeToInt (time: number | string) {
54 return hours * 3600 + minutes * 60 + seconds 58 return hours * 3600 + minutes * 60 + seconds
55} 59}
56 60
57function secondsToTime (seconds: number) { 61function secondsToTime (seconds: number, full = false, symbol?: string) {
58 let time = '' 62 let time = ''
59 63
60 let hours = Math.floor(seconds / 3600) 64 const hourSymbol = (symbol || 'h')
61 if (hours >= 1) time = hours + 'h' 65 const minuteSymbol = (symbol || 'm')
66 const secondsSymbol = full ? '' : 's'
67
68 const hours = Math.floor(seconds / 3600)
69 if (hours >= 1) time = hours + hourSymbol
70 else if (full) time = '0' + hourSymbol
62 71
63 seconds %= 3600 72 seconds %= 3600
64 let minutes = Math.floor(seconds / 60) 73 const minutes = Math.floor(seconds / 60)
65 if (minutes >= 1) time += minutes + 'm' 74 if (minutes >= 1 && minutes < 10 && full) time += '0' + minutes + minuteSymbol
75 else if (minutes >= 1) time += minutes + minuteSymbol
76 else if (full) time += '00' + minuteSymbol
66 77
67 seconds %= 60 78 seconds %= 60
68 if (seconds >= 1) time += seconds + 's' 79 if (seconds >= 1 && seconds < 10 && full) time += '0' + seconds + secondsSymbol
80 else if (seconds >= 1) time += seconds + secondsSymbol
81 else if (full) time += '00'
69 82
70 return time 83 return time
71} 84}
@@ -112,11 +125,27 @@ function videoFileMinByResolution (files: VideoFile[]) {
112 return min 125 return min
113} 126}
114 127
128function getRtcConfig () {
129 return {
130 iceServers: [
131 {
132 urls: 'stun:stun.stunprotocol.org'
133 },
134 {
135 urls: 'stun:stun.framasoft.org'
136 }
137 ]
138 }
139}
140
115// --------------------------------------------------------------------------- 141// ---------------------------------------------------------------------------
116 142
117export { 143export {
144 getRtcConfig,
118 toTitleCase, 145 toTitleCase,
119 timeToInt, 146 timeToInt,
147 secondsToTime,
148 isWebRTCDisabled,
120 buildVideoLink, 149 buildVideoLink,
121 buildVideoEmbed, 150 buildVideoEmbed,
122 videoFileMaxByResolution, 151 videoFileMaxByResolution,