]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/assets/player/videojs-components/theater-button.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / videojs-components / theater-button.ts
CommitLineData
f5fcd9f7 1import videojs, { VideoJsPlayer } from 'video.js'
2adfc7ea 2import { saveTheaterInStore, getStoredTheater } from '../peertube-player-local-storage'
054a103b 3
f5fcd9f7 4const Button = videojs.getComponent('Button')
054a103b
C
5class TheaterButton extends Button {
6
7 private static readonly THEATER_MODE_CLASS = 'vjs-theater-enabled'
8
f5fcd9f7 9 constructor (player: VideoJsPlayer, options: videojs.ComponentOptions) {
054a103b
C
10 super(player, options)
11
12 const enabled = getStoredTheater()
13 if (enabled === true) {
f5fcd9f7 14 this.player().addClass(TheaterButton.THEATER_MODE_CLASS)
9a18a625 15
054a103b
C
16 this.handleTheaterChange()
17 }
9a18a625 18
f5fcd9f7
C
19 this.controlText('Theater mode')
20
21 this.player().theaterEnabled = enabled
054a103b
C
22 }
23
24 buildCSSClass () {
25 return `vjs-theater-control ${super.buildCSSClass()}`
26 }
27
28 handleTheaterChange () {
9a18a625
C
29 const theaterEnabled = this.isTheaterEnabled()
30
31 if (theaterEnabled) {
054a103b
C
32 this.controlText('Normal mode')
33 } else {
34 this.controlText('Theater mode')
35 }
36
9a18a625
C
37 saveTheaterInStore(theaterEnabled)
38
39 this.player_.trigger('theaterChange', theaterEnabled)
054a103b
C
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
f5fcd9f7 53videojs.registerComponent('TheaterButton', TheaterButton)