X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=client%2Fsrc%2Fassets%2Fplayer%2Futils.ts;h=54f1313105e02562480c24630f2bf4d7f4f99038;hb=f0a3988066f72a28bb44520af072f18d91d77dde;hp=c872874820b2a316bd677f290655daf1031b3183;hpb=be0f59b4eec3c2c4dcd151e2b174be39dff1568e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index c87287482..54f131310 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts @@ -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,