]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/assets/player/resolution-menu-item.ts
Ensure youtubedl binary exists in ydl helper
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / resolution-menu-item.ts
1 import * as videojs from 'video.js'
2 import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
3
4 const MenuItem: VideoJSComponentInterface = videojsUntyped.getComponent('MenuItem')
5 class 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
17 player.peertube().on('videoFileUpdate', () => this.updateSelection())
18 player.peertube().on('autoResolutionUpdate', () => this.updateSelection())
19 }
20
21 handleClick (event) {
22 if (this.id === -1 && this.player_.peertube().isAutoResolutionForbidden()) return
23
24 super.handleClick(event)
25
26 // Auto resolution
27 if (this.id === -1) {
28 this.player_.peertube().enableAutoResolution()
29 return
30 }
31
32 this.player_.peertube().disableAutoResolution()
33 this.player_.peertube().updateResolution(this.id)
34 }
35
36 updateSelection () {
37 // Check if auto resolution is forbidden or not
38 if (this.id === -1) {
39 if (this.player_.peertube().isAutoResolutionForbidden()) {
40 this.addClass('disabled')
41 } else {
42 this.removeClass('disabled')
43 }
44 }
45
46 if (this.player_.peertube().isAutoResolutionOn()) {
47 this.selected(this.id === -1)
48 return
49 }
50
51 this.selected(this.player_.peertube().getCurrentResolutionId() === this.id)
52 }
53
54 getLabel () {
55 if (this.id === -1) {
56 return this.label + ' <small>' + this.player_.peertube().getCurrentResolutionLabel() + '</small>'
57 }
58
59 return this.label
60 }
61 }
62 MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem)
63
64 export { ResolutionMenuItem }