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