const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin')
class PeerTubePlugin extends Plugin {
- private readonly autoplay: boolean = false
- private readonly startTime: number = 0
private readonly videoViewUrl: string
private readonly videoDuration: number
private readonly CONSTANTS = {
private videoViewInterval: any
private userWatchingVideoInterval: any
- private qualityObservationTimer: any
private lastResolutionChange: ResolutionUpdateData
constructor (player: videojs.Player, options: PeerTubePluginOptions) {
super(player, options)
- this.startTime = timeToInt(options.startTime)
this.videoViewUrl = options.videoViewUrl
this.videoDuration = options.videoDuration
this.videoCaptions = options.videoCaptions
saveMuteInStore(this.player.muted())
})
+ if (options.stopTime) {
+ const stopTime = timeToInt(options.stopTime)
+ const self = this
+
+ this.player.on('timeupdate', function onTimeUpdate () {
+ if (self.player.currentTime() > stopTime) {
+ self.player.pause()
+ self.player.trigger('stopped')
+
+ self.player.off('timeupdate', onTimeUpdate)
+ }
+ })
+ }
+
this.player.textTracks().on('change', () => {
const showing = this.player.textTracks().tracks_.find((t: { kind: string, mode: string }) => {
return t.kind === 'captions' && t.mode === 'showing'
}
dispose () {
- clearTimeout(this.qualityObservationTimer)
-
- clearInterval(this.videoViewInterval)
-
+ if (this.videoViewInterval) clearInterval(this.videoViewInterval)
if (this.userWatchingVideoInterval) clearInterval(this.userWatchingVideoInterval)
}