aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/videojs-components
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
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')
-rw-r--r--client/src/assets/player/videojs-components/p2p-info-button.ts16
-rw-r--r--client/src/assets/player/videojs-components/resolution-menu-button.ts33
-rw-r--r--client/src/assets/player/videojs-components/resolution-menu-item.ts18
-rw-r--r--client/src/assets/player/videojs-components/settings-menu-item.ts10
4 files changed, 53 insertions, 24 deletions
diff --git a/client/src/assets/player/videojs-components/p2p-info-button.ts b/client/src/assets/player/videojs-components/p2p-info-button.ts
index 03a5d29f0..2fc4c4562 100644
--- a/client/src/assets/player/videojs-components/p2p-info-button.ts
+++ b/client/src/assets/player/videojs-components/p2p-info-button.ts
@@ -1,4 +1,4 @@
1import { VideoJSComponentInterface, videojsUntyped } from '../peertube-videojs-typings' 1import { PlayerNetworkInfo, VideoJSComponentInterface, videojsUntyped } from '../peertube-videojs-typings'
2import { bytes } from '../utils' 2import { bytes } from '../utils'
3 3
4const Button: VideoJSComponentInterface = videojsUntyped.getComponent('Button') 4const Button: VideoJSComponentInterface = videojsUntyped.getComponent('Button')
@@ -65,7 +65,7 @@ class P2pInfoButton extends Button {
65 subDivHttp.appendChild(subDivHttpText) 65 subDivHttp.appendChild(subDivHttpText)
66 div.appendChild(subDivHttp) 66 div.appendChild(subDivHttp)
67 67
68 this.player_.on('p2pInfo', (event: any, data: any) => { 68 this.player_.on('p2pInfo', (event: any, data: PlayerNetworkInfo) => {
69 // We are in HTTP fallback 69 // We are in HTTP fallback
70 if (!data) { 70 if (!data) {
71 subDivHttp.className = 'vjs-peertube-displayed' 71 subDivHttp.className = 'vjs-peertube-displayed'
@@ -74,11 +74,13 @@ class P2pInfoButton extends Button {
74 return 74 return
75 } 75 }
76 76
77 const downloadSpeed = bytes(data.downloadSpeed) 77 const p2pStats = data.p2p
78 const uploadSpeed = bytes(data.uploadSpeed) 78
79 const totalDownloaded = bytes(data.downloaded) 79 const downloadSpeed = bytes(p2pStats.downloadSpeed)
80 const totalUploaded = bytes(data.uploaded) 80 const uploadSpeed = bytes(p2pStats.uploadSpeed)
81 const numPeers = data.numPeers 81 const totalDownloaded = bytes(p2pStats.downloaded)
82 const totalUploaded = bytes(p2pStats.uploaded)
83 const numPeers = p2pStats.numPeers
82 84
83 subDivWebtorrent.title = this.player_.localize('Total downloaded: ') + totalDownloaded.join(' ') + '\n' + 85 subDivWebtorrent.title = this.player_.localize('Total downloaded: ') + totalDownloaded.join(' ') + '\n' +
84 this.player_.localize('Total uploaded: ' + totalUploaded.join(' ')) 86 this.player_.localize('Total uploaded: ' + totalUploaded.join(' '))
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'
diff --git a/client/src/assets/player/videojs-components/resolution-menu-item.ts b/client/src/assets/player/videojs-components/resolution-menu-item.ts
index cc1c79739..6c42fefd2 100644
--- a/client/src/assets/player/videojs-components/resolution-menu-item.ts
+++ b/client/src/assets/player/videojs-components/resolution-menu-item.ts
@@ -28,16 +28,12 @@ class ResolutionMenuItem extends MenuItem {
28 this.id = options.id 28 this.id = options.id
29 this.callback = options.callback 29 this.callback = options.callback
30 30
31 if (player.webtorrent) { 31 player.peertube().on('resolutionChange', (_: any, data: ResolutionUpdateData) => this.updateSelection(data))
32 player.webtorrent().on('videoFileUpdate', (_: any, data: ResolutionUpdateData) => this.updateSelection(data))
33 32
34 // We only want to disable the "Auto" item 33 // We only want to disable the "Auto" item
35 if (this.id === -1) { 34 if (this.id === -1) {
36 player.webtorrent().on('autoResolutionUpdate', (_: any, data: AutoResolutionUpdateData) => this.updateAutoResolution(data)) 35 player.peertube().on('autoResolutionChange', (_: any, data: AutoResolutionUpdateData) => this.updateAutoResolution(data))
37 }
38 } 36 }
39
40 // TODO: update on HLS change
41 } 37 }
42 38
43 handleClick (event: any) { 39 handleClick (event: any) {
@@ -46,12 +42,12 @@ class ResolutionMenuItem extends MenuItem {
46 42
47 super.handleClick(event) 43 super.handleClick(event)
48 44
49 this.callback(this.id) 45 this.callback(this.id, 'video')
50 } 46 }
51 47
52 updateSelection (data: ResolutionUpdateData) { 48 updateSelection (data: ResolutionUpdateData) {
53 if (this.id === -1) { 49 if (this.id === -1) {
54 this.currentResolutionLabel = this.labels[data.resolutionId] 50 this.currentResolutionLabel = this.labels[data.id]
55 } 51 }
56 52
57 // Automatic resolution only 53 // Automatic resolution only
@@ -60,7 +56,7 @@ class ResolutionMenuItem extends MenuItem {
60 return 56 return
61 } 57 }
62 58
63 this.selected(this.id === data.resolutionId) 59 this.selected(this.id === data.id)
64 } 60 }
65 61
66 updateAutoResolution (data: AutoResolutionUpdateData) { 62 updateAutoResolution (data: AutoResolutionUpdateData) {
diff --git a/client/src/assets/player/videojs-components/settings-menu-item.ts b/client/src/assets/player/videojs-components/settings-menu-item.ts
index b9a430290..f14959f9c 100644
--- a/client/src/assets/player/videojs-components/settings-menu-item.ts
+++ b/client/src/assets/player/videojs-components/settings-menu-item.ts
@@ -223,6 +223,11 @@ class SettingsMenuItem extends MenuItem {
223 this.subMenu.on('updateLabel', () => { 223 this.subMenu.on('updateLabel', () => {
224 this.update() 224 this.update()
225 }) 225 })
226 this.subMenu.on('menuChanged', () => {
227 this.bindClickEvents()
228 this.setSize()
229 this.update()
230 })
226 231
227 this.settingsSubMenuTitleEl_.innerHTML = this.player_.localize(this.subMenu.controlText_) 232 this.settingsSubMenuTitleEl_.innerHTML = this.player_.localize(this.subMenu.controlText_)
228 this.settingsSubMenuEl_.appendChild(this.subMenu.menu.el_) 233 this.settingsSubMenuEl_.appendChild(this.subMenu.menu.el_)
@@ -230,7 +235,7 @@ class SettingsMenuItem extends MenuItem {
230 this.update() 235 this.update()
231 236
232 this.createBackButton() 237 this.createBackButton()
233 this.getSize() 238 this.setSize()
234 this.bindClickEvents() 239 this.bindClickEvents()
235 240
236 // prefixed event listeners for CSS TransitionEnd 241 // prefixed event listeners for CSS TransitionEnd
@@ -292,8 +297,9 @@ class SettingsMenuItem extends MenuItem {
292 297
293 // save size of submenus on first init 298 // save size of submenus on first init
294 // if number of submenu items change dynamically more logic will be needed 299 // if number of submenu items change dynamically more logic will be needed
295 getSize () { 300 setSize () {
296 this.dialog.removeClass('vjs-hidden') 301 this.dialog.removeClass('vjs-hidden')
302 videojsUntyped.dom.removeClass(this.settingsSubMenuEl_, 'vjs-hidden')
297 this.size = this.settingsButton.getComponentSize(this.settingsSubMenuEl_) 303 this.size = this.settingsButton.getComponentSize(this.settingsSubMenuEl_)
298 this.setMargin() 304 this.setMargin()
299 this.dialog.addClass('vjs-hidden') 305 this.dialog.addClass('vjs-hidden')