NoImplicitAny flag true (#1157)
[oweals/peertube.git] / client / src / assets / player / resolution-menu-item.ts
1 import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
2
3 const MenuItem: VideoJSComponentInterface = videojsUntyped.getComponent('MenuItem')
4 class ResolutionMenuItem extends MenuItem {
5
6   constructor (player: any, options: any) {
7     const currentResolutionId = player.peertube().getCurrentResolutionId()
8     options.selectable = true
9     options.selected = options.id === currentResolutionId
10
11     super(player, options)
12
13     this.label = options.label
14     this.id = options.id
15
16     player.peertube().on('videoFileUpdate', () => this.updateSelection())
17     player.peertube().on('autoResolutionUpdate', () => this.updateSelection())
18   }
19
20   handleClick (event: any) {
21     if (this.id === -1 && this.player_.peertube().isAutoResolutionForbidden()) return
22
23     super.handleClick(event)
24
25     // Auto resolution
26     if (this.id === -1) {
27       this.player_.peertube().enableAutoResolution()
28       return
29     }
30
31     this.player_.peertube().disableAutoResolution()
32     this.player_.peertube().updateResolution(this.id)
33   }
34
35   updateSelection () {
36     // Check if auto resolution is forbidden or not
37     if (this.id === -1) {
38       if (this.player_.peertube().isAutoResolutionForbidden()) {
39         this.addClass('disabled')
40       } else {
41         this.removeClass('disabled')
42       }
43     }
44
45     if (this.player_.peertube().isAutoResolutionOn()) {
46       this.selected(this.id === -1)
47       return
48     }
49
50     this.selected(this.player_.peertube().getCurrentResolutionId() === this.id)
51   }
52
53   getLabel () {
54     if (this.id === -1) {
55       return this.label + ' <small>' + this.player_.peertube().getCurrentResolutionLabel() + '</small>'
56     }
57
58     return this.label
59   }
60 }
61 MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem)
62
63 export { ResolutionMenuItem }