]>
Commit | Line | Data |
---|---|---|
6cca7360 | 1 | import * as videojs from 'video.js' |
c6352f2c C |
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 | ||
b891f9bc | 17 | player.peertube().on('videoFileUpdate', () => this.updateSelection()) |
a8462c8e | 18 | player.peertube().on('autoResolutionUpdate', () => this.updateSelection()) |
c6352f2c C |
19 | } |
20 | ||
21 | handleClick (event) { | |
c4082b8b C |
22 | if (this.id === -1 && this.player_.peertube().isAutoResolutionForbidden()) return |
23 | ||
c6352f2c C |
24 | super.handleClick(event) |
25 | ||
a8462c8e C |
26 | // Auto resolution |
27 | if (this.id === -1) { | |
28 | this.player_.peertube().enableAutoResolution() | |
29 | return | |
30 | } | |
31 | ||
32 | this.player_.peertube().disableAutoResolution() | |
c6352f2c C |
33 | this.player_.peertube().updateResolution(this.id) |
34 | } | |
35 | ||
b891f9bc | 36 | updateSelection () { |
c4082b8b C |
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 | ||
a8462c8e C |
46 | if (this.player_.peertube().isAutoResolutionOn()) { |
47 | this.selected(this.id === -1) | |
48 | return | |
49 | } | |
50 | ||
c6352f2c C |
51 | this.selected(this.player_.peertube().getCurrentResolutionId() === this.id) |
52 | } | |
a8462c8e C |
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 | } | |
c6352f2c C |
61 | } |
62 | MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem) | |
63 | ||
64 | export { ResolutionMenuItem } |