]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/assets/player/shared/settings/resolution-menu-button.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / shared / settings / resolution-menu-button.ts
CommitLineData
512decf3 1import videojs from 'video.js'
c6352f2c
C
2import { ResolutionMenuItem } from './resolution-menu-item'
3
f5fcd9f7
C
4const Menu = videojs.getComponent('Menu')
5const MenuButton = videojs.getComponent('MenuButton')
c6352f2c 6class ResolutionMenuButton extends MenuButton {
f5fcd9f7 7 labelEl_: HTMLElement
c6352f2c 8
7e37e111 9 constructor (player: videojs.Player, options?: videojs.MenuButtonOptions) {
c6352f2c 10 super(player, options)
c6352f2c 11
f5fcd9f7
C
12 this.controlText('Quality')
13
e367da94 14 player.peertubeResolutions().on('resolutionsAdded', () => this.buildQualities())
2adfc7ea 15
e367da94
C
16 // For parent
17 player.peertubeResolutions().on('resolutionChanged', () => {
18 setTimeout(() => this.trigger('labelUpdated'))
19 })
c6352f2c
C
20 }
21
22 createEl () {
23 const el = super.createEl()
24
f5fcd9f7 25 this.labelEl_ = videojs.dom.createEl('div', {
2adfc7ea 26 className: 'vjs-resolution-value'
f5fcd9f7 27 }) as HTMLElement
c6352f2c
C
28
29 el.appendChild(this.labelEl_)
30
31 return el
32 }
33
34 updateARIAAttributes () {
35 this.el().setAttribute('aria-label', 'Quality')
36 }
37
38 createMenu () {
2adfc7ea
C
39 return new Menu(this.player_)
40 }
41
42 buildCSSClass () {
43 return super.buildCSSClass() + ' vjs-resolution-button'
44 }
3a6f351b 45
2adfc7ea
C
46 buildWrapperCSSClass () {
47 return 'vjs-resolution-control ' + super.buildWrapperCSSClass()
48 }
49
3b6f205c
C
50 private addClickListener (component: any) {
51 component.on('click', () => {
c4710631 52 const children = this.menu.children()
3b6f205c
C
53
54 for (const child of children) {
55 if (component !== child) {
f5fcd9f7 56 (child as videojs.MenuItem).selected(false)
3b6f205c
C
57 }
58 }
59 })
60 }
61
e367da94
C
62 private buildQualities () {
63 for (const d of this.player().peertubeResolutions().getResolutions()) {
8ff604c7 64 const label = d.label === '0p'
f5fcd9f7 65 ? this.player().localize('Audio-only')
3a149e9f
C
66 : d.label
67
2adfc7ea 68 this.menu.addChild(new ResolutionMenuItem(
c6352f2c
C
69 this.player_,
70 {
f552ca84
C
71 id: d.id + '',
72 resolutionId: d.id,
3a149e9f 73 label,
e367da94 74 selected: d.selected
c6352f2c
C
75 })
76 )
77 }
78
3b6f205c
C
79 for (const m of this.menu.children()) {
80 this.addClickListener(m)
81 }
82
83 this.trigger('menuChanged')
a8462c8e 84 }
c6352f2c 85}
e945b184 86
f5fcd9f7 87videojs.registerComponent('ResolutionMenuButton', ResolutionMenuButton)