aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/videojs-components/resolution-menu-button.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-01-24 10:16:30 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-02-11 09:13:02 +0100
commit3b6f205c34bb931de0323581edf991ca33256e6b (patch)
treef6ba40b7c666e38ff9c321906f04cb2c2630163e /client/src/assets/player/videojs-components/resolution-menu-button.ts
parent2adfc7ea9a1f858db874df9fe322e7ae833db77c (diff)
downloadPeerTube-3b6f205c34bb931de0323581edf991ca33256e6b.tar.gz
PeerTube-3b6f205c34bb931de0323581edf991ca33256e6b.tar.zst
PeerTube-3b6f205c34bb931de0323581edf991ca33256e6b.zip
Correctly implement p2p-media-loader
Diffstat (limited to 'client/src/assets/player/videojs-components/resolution-menu-button.ts')
-rw-r--r--client/src/assets/player/videojs-components/resolution-menu-button.ts33
1 files changed, 29 insertions, 4 deletions
diff --git a/client/src/assets/player/videojs-components/resolution-menu-button.ts b/client/src/assets/player/videojs-components/resolution-menu-button.ts
index 2847de470..abcc16411 100644
--- a/client/src/assets/player/videojs-components/resolution-menu-button.ts
+++ b/client/src/assets/player/videojs-components/resolution-menu-button.ts
@@ -14,11 +14,9 @@ class ResolutionMenuButton extends MenuButton {
14 super(player, options) 14 super(player, options)
15 this.player = player 15 this.player = player
16 16
17 player.on('loadedqualitydata', (e: any, data: any) => this.buildQualities(data)) 17 player.tech_.on('loadedqualitydata', (e: any, data: any) => this.buildQualities(data))
18 18
19 if (player.webtorrent) { 19 player.peertube().on('resolutionChange', () => setTimeout(() => this.trigger('updateLabel'), 0))
20 player.webtorrent().on('videoFileUpdate', () => setTimeout(() => this.trigger('updateLabel'), 0))
21 }
22 } 20 }
23 21
24 createEl () { 22 createEl () {
@@ -49,11 +47,32 @@ class ResolutionMenuButton extends MenuButton {
49 return 'vjs-resolution-control ' + super.buildWrapperCSSClass() 47 return 'vjs-resolution-control ' + super.buildWrapperCSSClass()
50 } 48 }
51 49
50 private addClickListener (component: any) {
51 component.on('click', () => {
52 let children = this.menu.children()
53
54 for (const child of children) {
55 if (component !== child) {
56 child.selected(false)
57 }
58 }
59 })
60 }
61
52 private buildQualities (data: LoadedQualityData) { 62 private buildQualities (data: LoadedQualityData) {
53 // The automatic resolution item will need other labels 63 // The automatic resolution item will need other labels
54 const labels: { [ id: number ]: string } = {} 64 const labels: { [ id: number ]: string } = {}
55 65
66 data.qualityData.video.sort((a, b) => {
67 if (a.id > b.id) return -1
68 if (a.id === b.id) return 0
69 return 1
70 })
71
56 for (const d of data.qualityData.video) { 72 for (const d of data.qualityData.video) {
73 // Skip auto resolution, we'll add it ourselves
74 if (d.id === -1) continue
75
57 this.menu.addChild(new ResolutionMenuItem( 76 this.menu.addChild(new ResolutionMenuItem(
58 this.player_, 77 this.player_,
59 { 78 {
@@ -77,6 +96,12 @@ class ResolutionMenuButton extends MenuButton {
77 selected: true // By default, in auto mode 96 selected: true // By default, in auto mode
78 } 97 }
79 )) 98 ))
99
100 for (const m of this.menu.children()) {
101 this.addClickListener(m)
102 }
103
104 this.trigger('menuChanged')
80 } 105 }
81} 106}
82ResolutionMenuButton.prototype.controlText_ = 'Quality' 107ResolutionMenuButton.prototype.controlText_ = 'Quality'