diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-14 14:28:20 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-14 14:36:35 +0100 |
commit | 57d6503286b114fee61b5e4725825e2490dcac29 (patch) | |
tree | 2d3d23f697b2986d7e41bb443754394296b66ec3 /client/src/assets/player/shared/common | |
parent | 9597920ee3d4ac99803e7107983ddf98a9dfb3c4 (diff) | |
download | PeerTube-57d6503286b114fee61b5e4725825e2490dcac29.tar.gz PeerTube-57d6503286b114fee61b5e4725825e2490dcac29.tar.zst PeerTube-57d6503286b114fee61b5e4725825e2490dcac29.zip |
Reorganize player files
Diffstat (limited to 'client/src/assets/player/shared/common')
-rw-r--r-- | client/src/assets/player/shared/common/index.ts | 1 | ||||
-rw-r--r-- | client/src/assets/player/shared/common/utils.ts | 66 |
2 files changed, 67 insertions, 0 deletions
diff --git a/client/src/assets/player/shared/common/index.ts b/client/src/assets/player/shared/common/index.ts new file mode 100644 index 000000000..9c56149ef --- /dev/null +++ b/client/src/assets/player/shared/common/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './utils' | |||
diff --git a/client/src/assets/player/shared/common/utils.ts b/client/src/assets/player/shared/common/utils.ts new file mode 100644 index 000000000..da7dda0c7 --- /dev/null +++ b/client/src/assets/player/shared/common/utils.ts | |||
@@ -0,0 +1,66 @@ | |||
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 | } | ||