]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/utils.ts
Add to playlist dropdown
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / utils.ts
index c872874820b2a316bd677f290655daf1031b3183..54f1313105e02562480c24630f2bf4d7f4f99038 100644 (file)
@@ -39,9 +39,10 @@ function buildVideoLink (time?: number, url?: string) {
 }
 
 function timeToInt (time: number | string) {
+  if (!time) return 0
   if (typeof time === 'number') return time
 
-  const reg = /^((\d+)h)?((\d+)m)?((\d+)s?)?$/
+  const reg = /^((\d+)[h:])?((\d+)[m:])?((\d+)s?)?$/
   const matches = time.match(reg)
 
   if (!matches) return 0
@@ -53,18 +54,27 @@ function timeToInt (time: number | string) {
   return hours * 3600 + minutes * 60 + seconds
 }
 
-function secondsToTime (seconds: number) {
+function secondsToTime (seconds: number, full = false, symbol?: string) {
   let time = ''
 
+  const hourSymbol = (symbol || 'h')
+  const minuteSymbol = (symbol || 'm')
+  const secondsSymbol = full ? '' : 's'
+
   let hours = Math.floor(seconds / 3600)
-  if (hours >= 1) time = hours + 'h'
+  if (hours >= 1) time = hours + hourSymbol
+  else if (full) time = '0' + hourSymbol
 
   seconds %= 3600
   let minutes = Math.floor(seconds / 60)
-  if (minutes >= 1) time += minutes + 'm'
+  if (minutes >= 1 && minutes < 10 && full) time += '0' + minutes + minuteSymbol
+  else if (minutes >= 1) time += minutes + minuteSymbol
+  else if (full) time += '00' + minuteSymbol
 
   seconds %= 60
-  if (seconds >= 1) time += seconds + 's'
+  if (seconds >= 1 && seconds < 10 && full) time += '0' + seconds + secondsSymbol
+  else if (seconds >= 1) time += seconds + secondsSymbol
+  else if (full) time += '00'
 
   return time
 }
@@ -111,11 +121,26 @@ function videoFileMinByResolution (files: VideoFile[]) {
   return min
 }
 
+function getRtcConfig () {
+  return {
+    iceServers: [
+      {
+        urls: 'stun:stun.stunprotocol.org'
+      },
+      {
+        urls: 'stun:stun.framasoft.org'
+      }
+    ]
+  }
+}
+
 // ---------------------------------------------------------------------------
 
 export {
+  getRtcConfig,
   toTitleCase,
   timeToInt,
+  secondsToTime,
   buildVideoLink,
   buildVideoEmbed,
   videoFileMaxByResolution,