aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-17 10:57:18 +0200
committerChocobozzz <me@florianbigard.com>2023-07-17 11:31:46 +0200
commit9a72e4fe9e362682b9afc7e959472bf7dab0f987 (patch)
treea1aac0f908af7653e8c828fb0e0025cdc5136fc4 /client/src/assets/player
parente29221f855a7135bcfb45720e3600c7401939abb (diff)
downloadPeerTube-9a72e4fe9e362682b9afc7e959472bf7dab0f987.tar.gz
PeerTube-9a72e4fe9e362682b9afc7e959472bf7dab0f987.tar.zst
PeerTube-9a72e4fe9e362682b9afc7e959472bf7dab0f987.zip
Improve settings menu label handler
Diffstat (limited to 'client/src/assets/player')
-rw-r--r--client/src/assets/player/shared/peertube/peertube-plugin.ts2
-rw-r--r--client/src/assets/player/shared/settings/resolution-menu-button.ts2
-rw-r--r--client/src/assets/player/shared/settings/settings-menu-item.ts47
3 files changed, 27 insertions, 24 deletions
diff --git a/client/src/assets/player/shared/peertube/peertube-plugin.ts b/client/src/assets/player/shared/peertube/peertube-plugin.ts
index c405e37e0..6c83d22bf 100644
--- a/client/src/assets/player/shared/peertube/peertube-plugin.ts
+++ b/client/src/assets/player/shared/peertube/peertube-plugin.ts
@@ -310,8 +310,6 @@ class PeerTubePlugin extends Plugin {
310 private setInactivityTimeout (timeout: number) { 310 private setInactivityTimeout (timeout: number) {
311 (this.player as any).cache_.inactivityTimeout = timeout 311 (this.player as any).cache_.inactivityTimeout = timeout
312 this.player.options_.inactivityTimeout = timeout 312 this.player.options_.inactivityTimeout = timeout
313
314 debugLogger('Set player inactivity to ' + timeout)
315 } 313 }
316 314
317 private initCaptions () { 315 private initCaptions () {
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 c39894284..ac947fdb1 100644
--- a/client/src/assets/player/shared/settings/resolution-menu-button.ts
+++ b/client/src/assets/player/shared/settings/resolution-menu-button.ts
@@ -64,7 +64,7 @@ class ResolutionMenuButton extends MenuButton {
64 update () { 64 update () {
65 super.update() 65 super.update()
66 66
67 this.trigger('menu-changed') 67 this.trigger('resolution-menu-changed')
68 } 68 }
69 69
70 buildCSSClass () { 70 buildCSSClass () {
diff --git a/client/src/assets/player/shared/settings/settings-menu-item.ts b/client/src/assets/player/shared/settings/settings-menu-item.ts
index 9916ae27f..9e4ad59c8 100644
--- a/client/src/assets/player/shared/settings/settings-menu-item.ts
+++ b/client/src/assets/player/shared/settings/settings-menu-item.ts
@@ -1,3 +1,4 @@
1import debug from 'debug'
1import videojs from 'video.js' 2import videojs from 'video.js'
2import { toTitleCase } from '../common' 3import { toTitleCase } from '../common'
3import { SettingsDialog } from './settings-dialog' 4import { SettingsDialog } from './settings-dialog'
@@ -5,8 +6,16 @@ import { SettingsButton } from './settings-menu-button'
5import { SettingsPanel } from './settings-panel' 6import { SettingsPanel } from './settings-panel'
6import { SettingsPanelChild } from './settings-panel-child' 7import { SettingsPanelChild } from './settings-panel-child'
7 8
9const debugLogger = debug('peertube:player:settings')
10
8const MenuItem = videojs.getComponent('MenuItem') 11const MenuItem = videojs.getComponent('MenuItem')
9const component = videojs.getComponent('Component') 12const Component = videojs.getComponent('Component')
13
14interface MenuItemExtended extends videojs.MenuItem {
15 isSelected_: boolean
16
17 getLabel?: () => string
18}
10 19
11export interface SettingsMenuItemOptions extends videojs.MenuItemOptions { 20export interface SettingsMenuItemOptions extends videojs.MenuItemOptions {
12 entry: string 21 entry: string
@@ -76,15 +85,15 @@ class SettingsMenuItem extends MenuItem {
76 85
77 if (subMenuName === 'CaptionsButton') { 86 if (subMenuName === 'CaptionsButton') {
78 player.on('captions-changed', () => { 87 player.on('captions-changed', () => {
79 // Wait menu component rebuild 88 setTimeout(() => this.rebuildAfterMenuChange())
80 setTimeout(() => {
81 this.rebuildAfterMenuChange()
82 }, 150)
83 }) 89 })
90
91 // Needed because 'captions-changed' event doesn't contain the selected caption yet
92 player.on('texttrackchange', this.submenuClickHandler)
84 } 93 }
85 94
86 if (subMenuName === 'ResolutionMenuButton') { 95 if (subMenuName === 'ResolutionMenuButton') {
87 this.subMenu.on('menu-changed', () => { 96 this.subMenu.on('resolution-menu-changed', () => {
88 this.rebuildAfterMenuChange() 97 this.rebuildAfterMenuChange()
89 }) 98 })
90 } 99 }
@@ -261,34 +270,28 @@ class SettingsMenuItem extends MenuItem {
261 } 270 }
262 271
263 update (event?: any) { 272 update (event?: any) {
264 const subMenu = this.subMenu.name()
265
266 // Playback rate menu button doesn't get a vjs-selected class 273 // Playback rate menu button doesn't get a vjs-selected class
267 // or sets options_['selected'] on the selected playback rate. 274 // or sets options_['selected'] on the selected playback rate.
268 // Thus we get the submenu value based on the labelEl of playbackRateMenuButton 275 // Thus we get the submenu value based on the labelEl of playbackRateMenuButton
269 if (subMenu === 'PlaybackRateMenuButton') { 276 if (this.subMenu.name() === 'PlaybackRateMenuButton') {
270 const html = (this.subMenu as any).labelEl_.innerHTML 277 this.settingsSubMenuValueEl_.innerHTML = (this.subMenu as any).labelEl_.textContent
271
272 setTimeout(() => {
273 this.settingsSubMenuValueEl_.innerHTML = html
274 }, 250)
275 } else { 278 } else {
276 // Loop through the submenu items to find the selected child 279 // Loop through the submenu items to find the selected child
277 for (const subMenuItem of this.subMenu.menu.children_) { 280 for (const subMenuItem of this.subMenu.menu.children_) {
278 if (!(subMenuItem instanceof component)) { 281 if (!(subMenuItem instanceof MenuItem)) {
279 continue 282 continue
280 } 283 }
281 284
282 if (subMenuItem.hasClass('vjs-selected')) { 285 const subMenuItemExtended = subMenuItem as MenuItemExtended
283 const subMenuItemUntyped = subMenuItem as any 286 if (subMenuItemExtended.isSelected_) {
284 287
285 // Prefer to use the function 288 // Prefer to use the function
286 if (typeof subMenuItemUntyped.getLabel === 'function') { 289 if (typeof subMenuItemExtended.getLabel === 'function') {
287 this.settingsSubMenuValueEl_.innerHTML = subMenuItemUntyped.getLabel() 290 this.settingsSubMenuValueEl_.innerHTML = subMenuItemExtended.getLabel()
288 break 291 break
289 } 292 }
290 293
291 this.settingsSubMenuValueEl_.innerHTML = this.player().localize(subMenuItemUntyped.options_.label) 294 this.settingsSubMenuValueEl_.innerHTML = this.player().localize(subMenuItemExtended.options_.label)
292 } 295 }
293 } 296 }
294 } 297 }
@@ -307,7 +310,7 @@ class SettingsMenuItem extends MenuItem {
307 310
308 bindClickEvents () { 311 bindClickEvents () {
309 for (const item of this.subMenu.menu.children()) { 312 for (const item of this.subMenu.menu.children()) {
310 if (!(item instanceof component)) { 313 if (!(item instanceof Component)) {
311 continue 314 continue
312 } 315 }
313 item.on([ 'tap', 'click' ], this.submenuClickHandler) 316 item.on([ 'tap', 'click' ], this.submenuClickHandler)
@@ -349,6 +352,8 @@ class SettingsMenuItem extends MenuItem {
349 } 352 }
350 353
351 private rebuildAfterMenuChange () { 354 private rebuildAfterMenuChange () {
355 debugLogger('Rebuilding menu ' + this.subMenu.name() + ' after change')
356
352 this.settingsSubMenuEl_.innerHTML = '' 357 this.settingsSubMenuEl_.innerHTML = ''
353 this.settingsSubMenuEl_.appendChild(this.subMenu.menu.el()) 358 this.settingsSubMenuEl_.appendChild(this.subMenu.menu.el())
354 this.update() 359 this.update()