1 import * as videojs from 'video.js'
2 import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
4 const MenuItem: VideoJSComponentInterface = videojsUntyped.getComponent('MenuItem')
5 class ResolutionMenuItem extends MenuItem {
7 constructor (player: videojs.Player, options) {
8 const currentResolutionId = player.peertube().getCurrentResolutionId()
9 options.selectable = true
10 options.selected = options.id === currentResolutionId
12 super(player, options)
14 this.label = options.label
17 player.peertube().on('videoFileUpdate', () => this.updateSelection())
18 player.peertube().on('autoResolutionUpdate', () => this.updateSelection())
22 if (this.id === -1 && this.player_.peertube().isAutoResolutionForbidden()) return
24 super.handleClick(event)
28 this.player_.peertube().enableAutoResolution()
32 this.player_.peertube().disableAutoResolution()
33 this.player_.peertube().updateResolution(this.id)
37 // Check if auto resolution is forbidden or not
39 if (this.player_.peertube().isAutoResolutionForbidden()) {
40 this.addClass('disabled')
42 this.removeClass('disabled')
46 if (this.player_.peertube().isAutoResolutionOn()) {
47 this.selected(this.id === -1)
51 this.selected(this.player_.peertube().getCurrentResolutionId() === this.id)
56 return this.label + ' <small>' + this.player_.peertube().getCurrentResolutionLabel() + '</small>'
62 MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem)
64 export { ResolutionMenuItem }