]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/assets/player/resolution-menu-button.ts
Fix transcoding
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / resolution-menu-button.ts
CommitLineData
c6352f2c
C
1import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
2import { ResolutionMenuItem } from './resolution-menu-item'
3
4const Menu: VideoJSComponentInterface = videojsUntyped.getComponent('Menu')
5const MenuButton: VideoJSComponentInterface = videojsUntyped.getComponent('MenuButton')
6class ResolutionMenuButton extends MenuButton {
7 label: HTMLElement
8
244b4ae3 9 constructor (player: any, options: any) {
c6352f2c 10 super(player, options)
c6352f2c
C
11 this.player = player
12
13 player.peertube().on('videoFileUpdate', () => this.updateLabel())
c4082b8b 14 player.peertube().on('autoResolutionUpdate', () => this.updateLabel())
c6352f2c
C
15 }
16
17 createEl () {
18 const el = super.createEl()
19
20 this.labelEl_ = videojsUntyped.dom.createEl('div', {
21 className: 'vjs-resolution-value',
a8462c8e 22 innerHTML: this.buildLabelHTML()
c6352f2c
C
23 })
24
25 el.appendChild(this.labelEl_)
26
27 return el
28 }
29
30 updateARIAAttributes () {
31 this.el().setAttribute('aria-label', 'Quality')
32 }
33
34 createMenu () {
b891f9bc 35 const menu = new Menu(this.player_)
c6352f2c 36 for (const videoFile of this.player_.peertube().videoFiles) {
3a6f351b
C
37 let label = videoFile.resolution.label
38 if (videoFile.fps && videoFile.fps >= 50) {
39 label += videoFile.fps
40 }
41
c6352f2c
C
42 menu.addChild(new ResolutionMenuItem(
43 this.player_,
44 {
45 id: videoFile.resolution.id,
3a6f351b 46 label,
c6352f2c
C
47 src: videoFile.magnetUri
48 })
49 )
50 }
51
a8462c8e
C
52 menu.addChild(new ResolutionMenuItem(
53 this.player_,
54 {
55 id: -1,
e945b184 56 label: this.player_.localize('Auto'),
a8462c8e
C
57 src: null
58 }
59 ))
60
c6352f2c
C
61 return menu
62 }
63
64 updateLabel () {
65 if (!this.labelEl_) return
66
a8462c8e 67 this.labelEl_.innerHTML = this.buildLabelHTML()
c6352f2c
C
68 }
69
70 buildCSSClass () {
71 return super.buildCSSClass() + ' vjs-resolution-button'
72 }
73
74 buildWrapperCSSClass () {
75 return 'vjs-resolution-control ' + super.buildWrapperCSSClass()
76 }
a8462c8e
C
77
78 private buildLabelHTML () {
79 return this.player_.peertube().getCurrentResolutionLabel()
80 }
c6352f2c 81}
e945b184
C
82ResolutionMenuButton.prototype.controlText_ = 'Quality'
83
c6352f2c 84MenuButton.registerComponent('ResolutionMenuButton', ResolutionMenuButton)