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'
7 const MenuItem: VideoJSComponentInterface = videojsUntyped.getComponent('MenuItem')
8 class ResolutionMenuItem extends MenuItem {
10 constructor (player: Player, options: any) {
11 const currentResolutionId = player.peertube().getCurrentResolutionId()
12 options.selectable = true
13 options.selected = options.id === currentResolutionId
15 super(player, options)
17 this.label = options.label
20 player.peertube().on('videoFileUpdate', () => this.updateSelection())
21 player.peertube().on('autoResolutionUpdate', () => this.updateSelection())
24 handleClick (event: any) {
25 if (this.id === -1 && this.player_.peertube().isAutoResolutionForbidden()) return
27 super.handleClick(event)
31 this.player_.peertube().enableAutoResolution()
35 this.player_.peertube().disableAutoResolution()
36 this.player_.peertube().updateResolution(this.id)
40 // Check if auto resolution is forbidden or not
42 if (this.player_.peertube().isAutoResolutionForbidden()) {
43 this.addClass('disabled')
45 this.removeClass('disabled')
49 if (this.player_.peertube().isAutoResolutionOn()) {
50 this.selected(this.id === -1)
54 this.selected(this.player_.peertube().getCurrentResolutionId() === this.id)
59 return this.label + ' <small>' + this.player_.peertube().getCurrentResolutionLabel() + '</small>'
65 MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem)
67 export { ResolutionMenuItem }