aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/shared/settings
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-06-29 15:55:00 +0200
committerChocobozzz <me@florianbigard.com>2023-07-10 16:08:28 +0200
commita1bd2b77d99cec5c27d38501f5f12f9dc339de17 (patch)
tree58b4666297e0b832a52f962541498af61319110a /client/src/assets/player/shared/settings
parent8ef866071f8109719e68647141d4c9e138438585 (diff)
downloadPeerTube-a1bd2b77d99cec5c27d38501f5f12f9dc339de17.tar.gz
PeerTube-a1bd2b77d99cec5c27d38501f5f12f9dc339de17.tar.zst
PeerTube-a1bd2b77d99cec5c27d38501f5f12f9dc339de17.zip
Remove webtorrent support from client
Diffstat (limited to 'client/src/assets/player/shared/settings')
-rw-r--r--client/src/assets/player/shared/settings/resolution-menu-button.ts77
-rw-r--r--client/src/assets/player/shared/settings/resolution-menu-item.ts38
-rw-r--r--client/src/assets/player/shared/settings/settings-dialog.ts12
-rw-r--r--client/src/assets/player/shared/settings/settings-menu-button.ts12
-rw-r--r--client/src/assets/player/shared/settings/settings-menu-item.ts86
5 files changed, 92 insertions, 133 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
diff --git a/client/src/assets/player/shared/settings/resolution-menu-item.ts b/client/src/assets/player/shared/settings/resolution-menu-item.ts
index c59b8b891..86387f533 100644
--- a/client/src/assets/player/shared/settings/resolution-menu-item.ts
+++ b/client/src/assets/player/shared/settings/resolution-menu-item.ts
@@ -10,35 +10,32 @@ class ResolutionMenuItem extends MenuItem {
10 readonly resolutionId: number 10 readonly resolutionId: number
11 private readonly label: string 11 private readonly label: string
12 12
13 private autoResolutionEnabled: boolean
14 private autoResolutionChosen: string 13 private autoResolutionChosen: string
15 14
16 constructor (player: videojs.Player, options?: ResolutionMenuItemOptions) { 15 private updateSelectionHandler: () => void
17 options.selectable = true
18 16
19 super(player, options) 17 constructor (player: videojs.Player, options?: ResolutionMenuItemOptions) {
18 super(player, { ...options, selectable: true })
20 19
21 this.autoResolutionEnabled = true
22 this.autoResolutionChosen = '' 20 this.autoResolutionChosen = ''
23 21
24 this.resolutionId = options.resolutionId 22 this.resolutionId = options.resolutionId
25 this.label = options.label 23 this.label = options.label
26 24
27 player.peertubeResolutions().on('resolutionChanged', () => this.updateSelection()) 25 this.updateSelectionHandler = () => this.updateSelection()
26 player.peertubeResolutions().on('resolutions-changed', this.updateSelectionHandler)
27 }
28
29 dispose () {
30 this.player().peertubeResolutions().off('resolutions-changed', this.updateSelectionHandler)
28 31
29 // We only want to disable the "Auto" item 32 super.dispose()
30 if (this.resolutionId === -1) {
31 player.peertubeResolutions().on('autoResolutionEnabledChanged', () => this.updateAutoResolution())
32 }
33 } 33 }
34 34
35 handleClick (event: any) { 35 handleClick (event: any) {
36 // Auto button disabled?
37 if (this.autoResolutionEnabled === false && this.resolutionId === -1) return
38
39 super.handleClick(event) 36 super.handleClick(event)
40 37
41 this.player().peertubeResolutions().select({ id: this.resolutionId, byEngine: false }) 38 this.player().peertubeResolutions().select({ id: this.resolutionId, fireCallback: true })
42 } 39 }
43 40
44 updateSelection () { 41 updateSelection () {
@@ -51,19 +48,6 @@ class ResolutionMenuItem extends MenuItem {
51 this.selected(this.resolutionId === selectedResolution.id) 48 this.selected(this.resolutionId === selectedResolution.id)
52 } 49 }
53 50
54 updateAutoResolution () {
55 const enabled = this.player().peertubeResolutions().isAutoResolutionEnabeld()
56
57 // Check if the auto resolution is enabled or not
58 if (enabled === false) {
59 this.addClass('disabled')
60 } else {
61 this.removeClass('disabled')
62 }
63
64 this.autoResolutionEnabled = enabled
65 }
66
67 getLabel () { 51 getLabel () {
68 if (this.resolutionId === -1) { 52 if (this.resolutionId === -1) {
69 return this.label + ' <small>' + this.autoResolutionChosen + '</small>' 53 return this.label + ' <small>' + this.autoResolutionChosen + '</small>'
diff --git a/client/src/assets/player/shared/settings/settings-dialog.ts b/client/src/assets/player/shared/settings/settings-dialog.ts
index f5fbbe7ad..ba39d0f45 100644
--- a/client/src/assets/player/shared/settings/settings-dialog.ts
+++ b/client/src/assets/player/shared/settings/settings-dialog.ts
@@ -28,6 +28,18 @@ class SettingsDialog extends Component {
28 'aria-describedby': dialogDescriptionId 28 'aria-describedby': dialogDescriptionId
29 }) 29 })
30 } 30 }
31
32 show () {
33 this.player().addClass('vjs-settings-dialog-opened')
34
35 super.show()
36 }
37
38 hide () {
39 this.player().removeClass('vjs-settings-dialog-opened')
40
41 super.hide()
42 }
31} 43}
32 44
33Component.registerComponent('SettingsDialog', SettingsDialog) 45Component.registerComponent('SettingsDialog', SettingsDialog)
diff --git a/client/src/assets/player/shared/settings/settings-menu-button.ts b/client/src/assets/player/shared/settings/settings-menu-button.ts
index 4cf29866b..9499a43eb 100644
--- a/client/src/assets/player/shared/settings/settings-menu-button.ts
+++ b/client/src/assets/player/shared/settings/settings-menu-button.ts
@@ -71,7 +71,7 @@ class SettingsButton extends Button {
71 } 71 }
72 } 72 }
73 73
74 onDisposeSettingsItem (event: any, name: string) { 74 onDisposeSettingsItem (_event: any, name: string) {
75 if (name === undefined) { 75 if (name === undefined) {
76 const children = this.menu.children() 76 const children = this.menu.children()
77 77
@@ -103,6 +103,8 @@ class SettingsButton extends Button {
103 if (this.isInIframe()) { 103 if (this.isInIframe()) {
104 window.removeEventListener('blur', this.documentClickHandler) 104 window.removeEventListener('blur', this.documentClickHandler)
105 } 105 }
106
107 super.dispose()
106 } 108 }
107 109
108 onAddSettingsItem (event: any, data: any) { 110 onAddSettingsItem (event: any, data: any) {
@@ -249,8 +251,8 @@ class SettingsButton extends Button {
249 } 251 }
250 252
251 resetChildren () { 253 resetChildren () {
252 for (const menuChild of this.menu.children()) { 254 for (const menuChild of this.menu.children() as SettingsMenuItem[]) {
253 (menuChild as SettingsMenuItem).reset() 255 menuChild.reset()
254 } 256 }
255 } 257 }
256 258
@@ -258,8 +260,8 @@ class SettingsButton extends Button {
258 * Hide all the sub menus 260 * Hide all the sub menus
259 */ 261 */
260 hideChildren () { 262 hideChildren () {
261 for (const menuChild of this.menu.children()) { 263 for (const menuChild of this.menu.children() as SettingsMenuItem[]) {
262 (menuChild as SettingsMenuItem).hideSubMenu() 264 menuChild.hideSubMenu()
263 } 265 }
264 } 266 }
265 267
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 288e3b233..9916ae27f 100644
--- a/client/src/assets/player/shared/settings/settings-menu-item.ts
+++ b/client/src/assets/player/shared/settings/settings-menu-item.ts
@@ -70,17 +70,22 @@ class SettingsMenuItem extends MenuItem {
70 this.build() 70 this.build()
71 71
72 // Update on rate change 72 // Update on rate change
73 player.on('ratechange', this.submenuClickHandler) 73 if (subMenuName === 'PlaybackRateMenuButton') {
74 player.on('ratechange', this.submenuClickHandler)
75 }
74 76
75 if (subMenuName === 'CaptionsButton') { 77 if (subMenuName === 'CaptionsButton') {
76 // Hack to regenerate captions on HTTP fallback 78 player.on('captions-changed', () => {
77 player.on('captionsChanged', () => { 79 // Wait menu component rebuild
78 setTimeout(() => { 80 setTimeout(() => {
79 this.settingsSubMenuEl_.innerHTML = '' 81 this.rebuildAfterMenuChange()
80 this.settingsSubMenuEl_.appendChild(this.subMenu.menu.el()) 82 }, 150)
81 this.update() 83 })
82 this.bindClickEvents() 84 }
83 }, 0) 85
86 if (subMenuName === 'ResolutionMenuButton') {
87 this.subMenu.on('menu-changed', () => {
88 this.rebuildAfterMenuChange()
84 }) 89 })
85 } 90 }
86 91
@@ -89,6 +94,12 @@ class SettingsMenuItem extends MenuItem {
89 }) 94 })
90 } 95 }
91 96
97 dispose () {
98 this.settingsSubMenuEl_.removeEventListener('transitionend', this.transitionEndHandler)
99
100 super.dispose()
101 }
102
92 eventHandlers () { 103 eventHandlers () {
93 this.submenuClickHandler = this.onSubmenuClick.bind(this) 104 this.submenuClickHandler = this.onSubmenuClick.bind(this)
94 this.transitionEndHandler = this.onTransitionEnd.bind(this) 105 this.transitionEndHandler = this.onTransitionEnd.bind(this)
@@ -190,27 +201,6 @@ class SettingsMenuItem extends MenuItem {
190 (button.el() as HTMLElement).innerHTML = this.player().localize(this.subMenu.controlText()) 201 (button.el() as HTMLElement).innerHTML = this.player().localize(this.subMenu.controlText())
191 } 202 }
192 203
193 /**
194 * Add/remove prefixed event listener for CSS Transition
195 *
196 * @method PrefixedEvent
197 */
198 PrefixedEvent (element: any, type: any, callback: any, action = 'addEvent') {
199 const prefix = [ 'webkit', 'moz', 'MS', 'o', '' ]
200
201 for (let p = 0; p < prefix.length; p++) {
202 if (!prefix[p]) {
203 type = type.toLowerCase()
204 }
205
206 if (action === 'addEvent') {
207 element.addEventListener(prefix[p] + type, callback, false)
208 } else if (action === 'removeEvent') {
209 element.removeEventListener(prefix[p] + type, callback, false)
210 }
211 }
212 }
213
214 onTransitionEnd (event: any) { 204 onTransitionEnd (event: any) {
215 if (event.propertyName !== 'margin-right') { 205 if (event.propertyName !== 'margin-right') {
216 return 206 return
@@ -254,12 +244,7 @@ class SettingsMenuItem extends MenuItem {
254 } 244 }
255 245
256 build () { 246 build () {
257 this.subMenu.on('labelUpdated', () => { 247 this.subMenu.on('label-updated', () => {
258 this.update()
259 })
260 this.subMenu.on('menuChanged', () => {
261 this.bindClickEvents()
262 this.setSize()
263 this.update() 248 this.update()
264 }) 249 })
265 250
@@ -272,25 +257,12 @@ class SettingsMenuItem extends MenuItem {
272 this.setSize() 257 this.setSize()
273 this.bindClickEvents() 258 this.bindClickEvents()
274 259
275 // prefixed event listeners for CSS TransitionEnd 260 this.settingsSubMenuEl_.addEventListener('transitionend', this.transitionEndHandler, false)
276 this.PrefixedEvent(
277 this.settingsSubMenuEl_,
278 'TransitionEnd',
279 this.transitionEndHandler,
280 'addEvent'
281 )
282 } 261 }
283 262
284 update (event?: any) { 263 update (event?: any) {
285 let target: HTMLElement = null
286 const subMenu = this.subMenu.name() 264 const subMenu = this.subMenu.name()
287 265
288 if (event && event.type === 'tap') {
289 target = event.target
290 } else if (event) {
291 target = event.currentTarget
292 }
293
294 // Playback rate menu button doesn't get a vjs-selected class 266 // Playback rate menu button doesn't get a vjs-selected class
295 // or sets options_['selected'] on the selected playback rate. 267 // or sets options_['selected'] on the selected playback rate.
296 // Thus we get the submenu value based on the labelEl of playbackRateMenuButton 268 // Thus we get the submenu value based on the labelEl of playbackRateMenuButton
@@ -321,6 +293,13 @@ class SettingsMenuItem extends MenuItem {
321 } 293 }
322 } 294 }
323 295
296 let target: HTMLElement = null
297 if (event && event.type === 'tap') {
298 target = event.target
299 } else if (event) {
300 target = event.currentTarget
301 }
302
324 if (target && !target.classList.contains('vjs-back-button')) { 303 if (target && !target.classList.contains('vjs-back-button')) {
325 this.settingsButton.hideDialog() 304 this.settingsButton.hideDialog()
326 } 305 }
@@ -369,6 +348,15 @@ class SettingsMenuItem extends MenuItem {
369 } 348 }
370 } 349 }
371 350
351 private rebuildAfterMenuChange () {
352 this.settingsSubMenuEl_.innerHTML = ''
353 this.settingsSubMenuEl_.appendChild(this.subMenu.menu.el())
354 this.update()
355 this.createBackButton()
356 this.setSize()
357 this.bindClickEvents()
358 }
359
372} 360}
373 361
374(SettingsMenuItem as any).prototype.contentElType = 'button' 362(SettingsMenuItem as any).prototype.contentElType = 'button'