1 // FIXME: something weird with our path definition in tsconfig and typings
3 import { Player } from 'video.js'
5 import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
6 import { ResolutionMenuItem } from './resolution-menu-item'
8 const Menu: VideoJSComponentInterface = videojsUntyped.getComponent('Menu')
9 const MenuButton: VideoJSComponentInterface = videojsUntyped.getComponent('MenuButton')
10 class ResolutionMenuButton extends MenuButton {
13 constructor (player: Player, options: any) {
14 super(player, options)
17 player.peertube().on('videoFileUpdate', () => this.updateLabel())
18 player.peertube().on('autoResolutionUpdate', () => this.updateLabel())
22 const el = super.createEl()
24 this.labelEl_ = videojsUntyped.dom.createEl('div', {
25 className: 'vjs-resolution-value',
26 innerHTML: this.buildLabelHTML()
29 el.appendChild(this.labelEl_)
34 updateARIAAttributes () {
35 this.el().setAttribute('aria-label', 'Quality')
39 const menu = new Menu(this.player_)
40 for (const videoFile of this.player_.peertube().videoFiles) {
41 let label = videoFile.resolution.label
42 if (videoFile.fps && videoFile.fps >= 50) {
43 label += videoFile.fps
46 menu.addChild(new ResolutionMenuItem(
49 id: videoFile.resolution.id,
51 src: videoFile.magnetUri
56 menu.addChild(new ResolutionMenuItem(
60 label: this.player_.localize('Auto'),
69 if (!this.labelEl_) return
71 this.labelEl_.innerHTML = this.buildLabelHTML()
75 return super.buildCSSClass() + ' vjs-resolution-button'
78 buildWrapperCSSClass () {
79 return 'vjs-resolution-control ' + super.buildWrapperCSSClass()
82 private buildLabelHTML () {
83 return this.player_.peertube().getCurrentResolutionLabel()
86 ResolutionMenuButton.prototype.controlText_ = 'Quality'
88 MenuButton.registerComponent('ResolutionMenuButton', ResolutionMenuButton)