2018-10-18 07:35:31 -05:00
|
|
|
// FIXME: something weird with our path definition in tsconfig and typings
|
|
|
|
// @ts-ignore
|
|
|
|
import * as videojs from 'video.js'
|
|
|
|
|
2019-01-23 08:36:45 -06:00
|
|
|
import { VideoJSComponentInterface, videojsUntyped } from '../peertube-videojs-typings'
|
|
|
|
import { saveTheaterInStore, getStoredTheater } from '../peertube-player-local-storage'
|
2018-06-11 09:49:56 -05:00
|
|
|
|
|
|
|
const Button: VideoJSComponentInterface = videojsUntyped.getComponent('Button')
|
|
|
|
class TheaterButton extends Button {
|
|
|
|
|
|
|
|
private static readonly THEATER_MODE_CLASS = 'vjs-theater-enabled'
|
|
|
|
|
2018-10-18 07:35:31 -05:00
|
|
|
constructor (player: videojs.Player, options: any) {
|
2018-06-11 09:49:56 -05:00
|
|
|
super(player, options)
|
|
|
|
|
|
|
|
const enabled = getStoredTheater()
|
|
|
|
if (enabled === true) {
|
|
|
|
this.player_.addClass(TheaterButton.THEATER_MODE_CLASS)
|
2019-03-18 04:26:53 -05:00
|
|
|
|
2018-06-11 09:49:56 -05:00
|
|
|
this.handleTheaterChange()
|
|
|
|
}
|
2019-03-18 04:26:53 -05:00
|
|
|
|
|
|
|
this.player_.theaterEnabled = enabled
|
2018-06-11 09:49:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
buildCSSClass () {
|
|
|
|
return `vjs-theater-control ${super.buildCSSClass()}`
|
|
|
|
}
|
|
|
|
|
|
|
|
handleTheaterChange () {
|
2019-03-18 04:26:53 -05:00
|
|
|
const theaterEnabled = this.isTheaterEnabled()
|
|
|
|
|
|
|
|
if (theaterEnabled) {
|
2018-06-11 09:49:56 -05:00
|
|
|
this.controlText('Normal mode')
|
|
|
|
} else {
|
|
|
|
this.controlText('Theater mode')
|
|
|
|
}
|
|
|
|
|
2019-03-18 04:26:53 -05:00
|
|
|
saveTheaterInStore(theaterEnabled)
|
|
|
|
|
|
|
|
this.player_.trigger('theaterChange', theaterEnabled)
|
2018-06-11 09:49:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
handleClick () {
|
|
|
|
this.player_.toggleClass(TheaterButton.THEATER_MODE_CLASS)
|
|
|
|
|
|
|
|
this.handleTheaterChange()
|
|
|
|
}
|
|
|
|
|
|
|
|
private isTheaterEnabled () {
|
|
|
|
return this.player_.hasClass(TheaterButton.THEATER_MODE_CLASS)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TheaterButton.prototype.controlText_ = 'Theater mode'
|
|
|
|
|
|
|
|
TheaterButton.registerComponent('TheaterButton', TheaterButton)
|