1 import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
3 const MenuItem: VideoJSComponentInterface = videojsUntyped.getComponent('MenuItem')
4 class ResolutionMenuItem extends MenuItem {
6 constructor (player: any, options: any) {
7 const currentResolutionId = player.peertube().getCurrentResolutionId()
8 options.selectable = true
9 options.selected = options.id === currentResolutionId
11 super(player, options)
13 this.label = options.label
16 player.peertube().on('videoFileUpdate', () => this.updateSelection())
17 player.peertube().on('autoResolutionUpdate', () => this.updateSelection())
20 handleClick (event: any) {
21 if (this.id === -1 && this.player_.peertube().isAutoResolutionForbidden()) return
23 super.handleClick(event)
27 this.player_.peertube().enableAutoResolution()
31 this.player_.peertube().disableAutoResolution()
32 this.player_.peertube().updateResolution(this.id)
36 // Check if auto resolution is forbidden or not
38 if (this.player_.peertube().isAutoResolutionForbidden()) {
39 this.addClass('disabled')
41 this.removeClass('disabled')
45 if (this.player_.peertube().isAutoResolutionOn()) {
46 this.selected(this.id === -1)
50 this.selected(this.player_.peertube().getCurrentResolutionId() === this.id)
55 return this.label + ' <small>' + this.player_.peertube().getCurrentResolutionLabel() + '</small>'
61 MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem)
63 export { ResolutionMenuItem }