aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/shared/settings/resolution-menu-button.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets/player/shared/settings/resolution-menu-button.ts')
-rw-r--r--client/src/assets/player/shared/settings/resolution-menu-button.ts77
1 files changed, 25 insertions, 52 deletions
diff --git a/client/src/assets/player/shared/settings/resolution-menu-button.ts b/client/src/assets/player/shared/settings/resolution-menu-button.ts
index 672411c11..c39894284 100644
--- a/client/src/assets/player/shared/settings/resolution-menu-button.ts
+++ b/client/src/assets/player/shared/settings/resolution-menu-button.ts
@@ -11,12 +11,12 @@ class ResolutionMenuButton extends MenuButton {
11 11
12 this.controlText('Quality') 12 this.controlText('Quality')
13 13
14 player.peertubeResolutions().on('resolutionsAdded', () => this.buildQualities()) 14 player.peertubeResolutions().on('resolutions-added', () => this.update())
15 player.peertubeResolutions().on('resolutionRemoved', () => this.cleanupQualities()) 15 player.peertubeResolutions().on('resolutions-removed', () => this.update())
16 16
17 // For parent 17 // For parent
18 player.peertubeResolutions().on('resolutionChanged', () => { 18 player.peertubeResolutions().on('resolutions-changed', () => {
19 setTimeout(() => this.trigger('labelUpdated')) 19 setTimeout(() => this.trigger('label-updated'))
20 }) 20 })
21 } 21 }
22 22
@@ -37,69 +37,42 @@ class ResolutionMenuButton extends MenuButton {
37 } 37 }
38 38
39 createMenu () { 39 createMenu () {
40 return new Menu(this.player_) 40 const menu: videojs.Menu = new Menu(this.player_, { menuButton: this })
41 } 41 const resolutions = this.player().peertubeResolutions().getResolutions()
42
43 buildCSSClass () {
44 return super.buildCSSClass() + ' vjs-resolution-button'
45 }
46
47 buildWrapperCSSClass () {
48 return 'vjs-resolution-control ' + super.buildWrapperCSSClass()
49 }
50
51 private addClickListener (component: any) {
52 component.on('click', () => {
53 const children = this.menu.children()
54
55 for (const child of children) {
56 if (component !== child) {
57 (child as videojs.MenuItem).selected(false)
58 }
59 }
60 })
61 }
62 42
63 private buildQualities () { 43 for (const r of resolutions) {
64 for (const d of this.player().peertubeResolutions().getResolutions()) { 44 const label = r.label === '0p'
65 const label = d.label === '0p'
66 ? this.player().localize('Audio-only') 45 ? this.player().localize('Audio-only')
67 : d.label 46 : r.label
68 47
69 this.menu.addChild(new ResolutionMenuItem( 48 const component = new ResolutionMenuItem(
70 this.player_, 49 this.player_,
71 { 50 {
72 id: d.id + '', 51 id: r.id + '',
73 resolutionId: d.id, 52 resolutionId: r.id,
74 label, 53 label,
75 selected: d.selected 54 selected: r.selected
76 }) 55 }
77 ) 56 )
78 }
79 57
80 for (const m of this.menu.children()) { 58 menu.addItem(component)
81 this.addClickListener(m)
82 } 59 }
83 60
84 this.trigger('menuChanged') 61 return menu
85 } 62 }
86 63
87 private cleanupQualities () { 64 update () {
88 const resolutions = this.player().peertubeResolutions().getResolutions() 65 super.update()
89
90 this.menu.children().forEach((children: ResolutionMenuItem) => {
91 if (children.resolutionId === undefined) {
92 return
93 }
94 66
95 if (resolutions.find(r => r.id === children.resolutionId)) { 67 this.trigger('menu-changed')
96 return 68 }
97 }
98 69
99 this.menu.removeChild(children) 70 buildCSSClass () {
100 }) 71 return super.buildCSSClass() + ' vjs-resolution-button'
72 }
101 73
102 this.trigger('menuChanged') 74 buildWrapperCSSClass () {
75 return 'vjs-resolution-control ' + super.buildWrapperCSSClass()
103 } 76 }
104} 77}
105 78