]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/assets/player/resolution-menu-item.ts
Fix auto quality with http fallback
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / resolution-menu-item.ts
CommitLineData
c6352f2c
C
1import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
2
3const MenuItem: VideoJSComponentInterface = videojsUntyped.getComponent('MenuItem')
4class ResolutionMenuItem extends MenuItem {
5
6 constructor (player: videojs.Player, options) {
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
b891f9bc 16 player.peertube().on('videoFileUpdate', () => this.updateSelection())
a8462c8e 17 player.peertube().on('autoResolutionUpdate', () => this.updateSelection())
c6352f2c
C
18 }
19
20 handleClick (event) {
21 super.handleClick(event)
22
a8462c8e
C
23 // Auto resolution
24 if (this.id === -1) {
25 this.player_.peertube().enableAutoResolution()
26 return
27 }
28
29 this.player_.peertube().disableAutoResolution()
c6352f2c
C
30 this.player_.peertube().updateResolution(this.id)
31 }
32
b891f9bc 33 updateSelection () {
a8462c8e
C
34 if (this.player_.peertube().isAutoResolutionOn()) {
35 this.selected(this.id === -1)
36 return
37 }
38
c6352f2c
C
39 this.selected(this.player_.peertube().getCurrentResolutionId() === this.id)
40 }
a8462c8e
C
41
42 getLabel () {
43 if (this.id === -1) {
44 return this.label + ' <small>' + this.player_.peertube().getCurrentResolutionLabel() + '</small>'
45 }
46
47 return this.label
48 }
c6352f2c
C
49}
50MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem)
51
52export { ResolutionMenuItem }