]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/assets/player/resolution-menu-item.ts
Fix transcoding
[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
244b4ae3 6 constructor (player: any, options: any) {
c6352f2c
C
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
244b4ae3 20 handleClick (event: any) {
c4082b8b
C
21 if (this.id === -1 && this.player_.peertube().isAutoResolutionForbidden()) return
22
c6352f2c
C
23 super.handleClick(event)
24
a8462c8e
C
25 // Auto resolution
26 if (this.id === -1) {
27 this.player_.peertube().enableAutoResolution()
28 return
29 }
30
31 this.player_.peertube().disableAutoResolution()
c6352f2c
C
32 this.player_.peertube().updateResolution(this.id)
33 }
34
b891f9bc 35 updateSelection () {
c4082b8b
C
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
a8462c8e
C
45 if (this.player_.peertube().isAutoResolutionOn()) {
46 this.selected(this.id === -1)
47 return
48 }
49
c6352f2c
C
50 this.selected(this.player_.peertube().getCurrentResolutionId() === this.id)
51 }
a8462c8e
C
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 }
c6352f2c
C
60}
61MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem)
62
63export { ResolutionMenuItem }