]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/assets/player/shared/common/utils.ts
Fix video right check
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / shared / common / utils.ts
1 import { VideoFile } from '@shared/models'
2
3 function toTitleCase (str: string) {
4 return str.charAt(0).toUpperCase() + str.slice(1)
5 }
6
7 // 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
9 const dictionaryBytes: Array<{max: number, type: string}> = [
10 { max: 1024, type: 'B' },
11 { max: 1048576, type: 'KB' },
12 { max: 1073741824, type: 'MB' },
13 { max: 1.0995116e12, type: 'GB' }
14 ]
15 function bytes (value: number) {
16 const format = dictionaryBytes.find(d => value < d.max) || dictionaryBytes[dictionaryBytes.length - 1]
17 const calc = Math.floor(value / (format.max / 1024)).toString()
18
19 return [ calc, format.type ]
20 }
21
22 function videoFileMaxByResolution (files: VideoFile[]) {
23 let max = files[0]
24
25 for (let i = 1; i < files.length; i++) {
26 const file = files[i]
27 if (max.resolution.id < file.resolution.id) max = file
28 }
29
30 return max
31 }
32
33 function videoFileMinByResolution (files: VideoFile[]) {
34 let min = files[0]
35
36 for (let i = 1; i < files.length; i++) {
37 const file = files[i]
38 if (min.resolution.id > file.resolution.id) min = file
39 }
40
41 return min
42 }
43
44 function getRtcConfig () {
45 return {
46 iceServers: [
47 {
48 urls: 'stun:stun.stunprotocol.org'
49 },
50 {
51 urls: 'stun:stun.framasoft.org'
52 }
53 ]
54 }
55 }
56
57 // ---------------------------------------------------------------------------
58
59 export {
60 getRtcConfig,
61 toTitleCase,
62
63 videoFileMaxByResolution,
64 videoFileMinByResolution,
65 bytes
66 }