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