Disable auto resolution on HTTP fallback
[oweals/peertube.git] / client / src / assets / player / resolution-menu-button.ts
1 import * as videojs from 'video.js'
2 import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
3 import { ResolutionMenuItem } from './resolution-menu-item'
4
5 const Menu: VideoJSComponentInterface = videojsUntyped.getComponent('Menu')
6 const MenuButton: VideoJSComponentInterface = videojsUntyped.getComponent('MenuButton')
7 class ResolutionMenuButton extends MenuButton {
8   label: HTMLElement
9
10   constructor (player: videojs.Player, options) {
11     super(player, options)
12     this.player = player
13
14     player.peertube().on('videoFileUpdate', () => this.updateLabel())
15     player.peertube().on('autoResolutionUpdate', () => this.updateLabel())
16   }
17
18   createEl () {
19     const el = super.createEl()
20
21     this.labelEl_ = videojsUntyped.dom.createEl('div', {
22       className: 'vjs-resolution-value',
23       innerHTML: this.buildLabelHTML()
24     })
25
26     el.appendChild(this.labelEl_)
27
28     return el
29   }
30
31   updateARIAAttributes () {
32     this.el().setAttribute('aria-label', 'Quality')
33   }
34
35   createMenu () {
36     const menu = new Menu(this.player_)
37     for (const videoFile of this.player_.peertube().videoFiles) {
38       menu.addChild(new ResolutionMenuItem(
39         this.player_,
40         {
41           id: videoFile.resolution.id,
42           label: videoFile.resolution.label,
43           src: videoFile.magnetUri
44         })
45       )
46     }
47
48     menu.addChild(new ResolutionMenuItem(
49       this.player_,
50       {
51         id: -1,
52         label: this.player_.localize('Auto'),
53         src: null
54       }
55     ))
56
57     return menu
58   }
59
60   updateLabel () {
61     if (!this.labelEl_) return
62
63     this.labelEl_.innerHTML = this.buildLabelHTML()
64   }
65
66   buildCSSClass () {
67     return super.buildCSSClass() + ' vjs-resolution-button'
68   }
69
70   buildWrapperCSSClass () {
71     return 'vjs-resolution-control ' + super.buildWrapperCSSClass()
72   }
73
74   private buildLabelHTML () {
75     return this.player_.peertube().getCurrentResolutionLabel()
76   }
77 }
78 ResolutionMenuButton.prototype.controlText_ = 'Quality'
79
80 MenuButton.registerComponent('ResolutionMenuButton', ResolutionMenuButton)