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