diff options
Diffstat (limited to 'client/src/assets/player/shared/control-bar/theater-button.ts')
-rw-r--r-- | client/src/assets/player/shared/control-bar/theater-button.ts | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/client/src/assets/player/shared/control-bar/theater-button.ts b/client/src/assets/player/shared/control-bar/theater-button.ts new file mode 100644 index 000000000..56c349d6b --- /dev/null +++ b/client/src/assets/player/shared/control-bar/theater-button.ts | |||
@@ -0,0 +1,53 @@ | |||
1 | import videojs from 'video.js' | ||
2 | import { getStoredTheater, saveTheaterInStore } 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: videojs.Player, 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) | ||