PeerTube_original/client/src/assets/player/resolution-menu-button.ts
BO41 244b4ae397 NoImplicitAny flag true (#1157)
this enables the `noImplicitAny` flag in the Typescript compiler

> When the noImplicitAny flag is true and the TypeScript compiler cannot infer the type, it still generates the JavaScript files, but it also reports an error. Many seasoned developers prefer this stricter setting because type checking catches more unintentional errors at compile time.

closes: #1131
replaces #1137
2018-10-18 09:08:59 +02:00

85 lines
2.1 KiB
TypeScript

import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
import { ResolutionMenuItem } from './resolution-menu-item'
const Menu: VideoJSComponentInterface = videojsUntyped.getComponent('Menu')
const MenuButton: VideoJSComponentInterface = videojsUntyped.getComponent('MenuButton')
class ResolutionMenuButton extends MenuButton {
label: HTMLElement
constructor (player: any, options: any) {
super(player, options)
this.player = player
player.peertube().on('videoFileUpdate', () => this.updateLabel())
player.peertube().on('autoResolutionUpdate', () => this.updateLabel())
}
createEl () {
const el = super.createEl()
this.labelEl_ = videojsUntyped.dom.createEl('div', {
className: 'vjs-resolution-value',
innerHTML: this.buildLabelHTML()
})
el.appendChild(this.labelEl_)
return el
}
updateARIAAttributes () {
this.el().setAttribute('aria-label', 'Quality')
}
createMenu () {
const menu = new Menu(this.player_)
for (const videoFile of this.player_.peertube().videoFiles) {
let label = videoFile.resolution.label
if (videoFile.fps && videoFile.fps >= 50) {
label += videoFile.fps
}
menu.addChild(new ResolutionMenuItem(
this.player_,
{
id: videoFile.resolution.id,
label,
src: videoFile.magnetUri
})
)
}
menu.addChild(new ResolutionMenuItem(
this.player_,
{
id: -1,
label: this.player_.localize('Auto'),
src: null
}
))
return menu
}
updateLabel () {
if (!this.labelEl_) return
this.labelEl_.innerHTML = this.buildLabelHTML()
}
buildCSSClass () {
return super.buildCSSClass() + ' vjs-resolution-button'
}
buildWrapperCSSClass () {
return 'vjs-resolution-control ' + super.buildWrapperCSSClass()
}
private buildLabelHTML () {
return this.player_.peertube().getCurrentResolutionLabel()
}
}
ResolutionMenuButton.prototype.controlText_ = 'Quality'
MenuButton.registerComponent('ResolutionMenuButton', ResolutionMenuButton)