]>
Commit | Line | Data |
---|---|---|
1 | import videojs, { VideoJsPlayer } from 'video.js' | |
2 | import { saveTheaterInStore, getStoredTheater } from '../peertube-player-local-storage' | |
3 | ||
4 | const Button = videojs.getComponent('Button') | |
5 | class TheaterButton extends Button { | |
6 | ||
7 | private static readonly THEATER_MODE_CLASS = 'vjs-theater-enabled' | |
8 | ||
9 | constructor (player: VideoJsPlayer, options: videojs.ComponentOptions) { | |
10 | super(player, options) | |
11 | ||
12 | const enabled = getStoredTheater() | |
13 | if (enabled === true) { | |
14 | this.player().addClass(TheaterButton.THEATER_MODE_CLASS) | |
15 | ||
16 | this.handleTheaterChange() | |
17 | } | |
18 | ||
19 | this.controlText('Theater mode') | |
20 | ||
21 | this.player().theaterEnabled = enabled | |
22 | } | |
23 | ||
24 | buildCSSClass () { | |
25 | return `vjs-theater-control ${super.buildCSSClass()}` | |
26 | } | |
27 | ||
28 | handleTheaterChange () { | |
29 | const theaterEnabled = this.isTheaterEnabled() | |
30 | ||
31 | if (theaterEnabled) { | |
32 | this.controlText('Normal mode') | |
33 | } else { | |
34 | this.controlText('Theater mode') | |
35 | } | |
36 | ||
37 | saveTheaterInStore(theaterEnabled) | |
38 | ||
39 | this.player_.trigger('theaterChange', theaterEnabled) | |
40 | } | |
41 | ||
42 | handleClick () { | |
43 | this.player_.toggleClass(TheaterButton.THEATER_MODE_CLASS) | |
44 | ||
45 | this.handleTheaterChange() | |
46 | } | |
47 | ||
48 | private isTheaterEnabled () { | |
49 | return this.player_.hasClass(TheaterButton.THEATER_MODE_CLASS) | |
50 | } | |
51 | } | |
52 | ||
53 | videojs.registerComponent('TheaterButton', TheaterButton) |