aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/peertube-resolutions-plugin.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-03-14 14:28:20 +0100
committerChocobozzz <me@florianbigard.com>2022-03-14 14:36:35 +0100
commit57d6503286b114fee61b5e4725825e2490dcac29 (patch)
tree2d3d23f697b2986d7e41bb443754394296b66ec3 /client/src/assets/player/peertube-resolutions-plugin.ts
parent9597920ee3d4ac99803e7107983ddf98a9dfb3c4 (diff)
downloadPeerTube-57d6503286b114fee61b5e4725825e2490dcac29.tar.gz
PeerTube-57d6503286b114fee61b5e4725825e2490dcac29.tar.zst
PeerTube-57d6503286b114fee61b5e4725825e2490dcac29.zip
Reorganize player files
Diffstat (limited to 'client/src/assets/player/peertube-resolutions-plugin.ts')
-rw-r--r--client/src/assets/player/peertube-resolutions-plugin.ts88
1 files changed, 0 insertions, 88 deletions
diff --git a/client/src/assets/player/peertube-resolutions-plugin.ts b/client/src/assets/player/peertube-resolutions-plugin.ts
deleted file mode 100644
index cc36f18f3..000000000
--- a/client/src/assets/player/peertube-resolutions-plugin.ts
+++ /dev/null
@@ -1,88 +0,0 @@
1import videojs from 'video.js'
2import { PeerTubeResolution } from './peertube-videojs-typings'
3
4const Plugin = videojs.getPlugin('plugin')
5
6class PeerTubeResolutionsPlugin extends Plugin {
7 private currentSelection: PeerTubeResolution
8 private resolutions: PeerTubeResolution[] = []
9
10 private autoResolutionChosenId: number
11 private autoResolutionEnabled = true
12
13 add (resolutions: PeerTubeResolution[]) {
14 for (const r of resolutions) {
15 this.resolutions.push(r)
16 }
17
18 this.currentSelection = this.getSelected()
19
20 this.sort()
21 this.trigger('resolutionsAdded')
22 }
23
24 getResolutions () {
25 return this.resolutions
26 }
27
28 getSelected () {
29 return this.resolutions.find(r => r.selected)
30 }
31
32 getAutoResolutionChosen () {
33 return this.resolutions.find(r => r.id === this.autoResolutionChosenId)
34 }
35
36 select (options: {
37 id: number
38 byEngine: boolean
39 autoResolutionChosenId?: number
40 }) {
41 const { id, autoResolutionChosenId, byEngine } = options
42
43 if (this.currentSelection?.id === id && this.autoResolutionChosenId === autoResolutionChosenId) return
44
45 this.autoResolutionChosenId = autoResolutionChosenId
46
47 for (const r of this.resolutions) {
48 r.selected = r.id === id
49
50 if (r.selected) {
51 this.currentSelection = r
52
53 if (!byEngine) r.selectCallback()
54 }
55 }
56
57 this.trigger('resolutionChanged')
58 }
59
60 disableAutoResolution () {
61 this.autoResolutionEnabled = false
62 this.trigger('autoResolutionEnabledChanged')
63 }
64
65 enabledAutoResolution () {
66 this.autoResolutionEnabled = true
67 this.trigger('autoResolutionEnabledChanged')
68 }
69
70 isAutoResolutionEnabeld () {
71 return this.autoResolutionEnabled
72 }
73
74 private sort () {
75 this.resolutions.sort((a, b) => {
76 if (a.id === -1) return 1
77 if (b.id === -1) return -1
78
79 if (a.height > b.height) return -1
80 if (a.height === b.height) return 0
81 return 1
82 })
83 }
84
85}
86
87videojs.registerPlugin('peertubeResolutions', PeerTubeResolutionsPlugin)
88export { PeerTubeResolutionsPlugin }