X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fassets%2Fplayer%2Fpeertube-plugin.ts;h=dd9408c8e280b37df8803cc3b9d96ddb36af24ef;hb=5efab5467cacb4cce584e2d36e4133a701d8c983;hp=f83d9094a40124763806a493aa8306859e8bcc33;hpb=3b6f205c34bb931de0323581edf991ca33256e6b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/assets/player/peertube-plugin.ts b/client/src/assets/player/peertube-plugin.ts index f83d9094a..dd9408c8e 100644 --- a/client/src/assets/player/peertube-plugin.ts +++ b/client/src/assets/player/peertube-plugin.ts @@ -22,8 +22,6 @@ import { 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 = { @@ -36,28 +34,30 @@ class PeerTubePlugin extends Plugin { 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 - if (this.autoplay === true) this.player.addClass('vjs-has-autoplay') + if (options.autoplay === true) this.player.addClass('vjs-has-autoplay') + + this.player.on('autoplay-failure', () => { + this.player.removeClass('vjs-has-autoplay') + }) this.player.ready(() => { const playerOptions = this.player.options_ - if (this.player.webtorrent) { + if (options.mode === 'webtorrent') { this.player.webtorrent().on('resolutionChange', (_: any, d: any) => this.handleResolutionChange(d)) this.player.webtorrent().on('autoResolutionChange', (_: any, d: any) => this.trigger('autoResolutionChange', d)) } - if (this.player.p2pMediaLoader) { + if (options.mode === 'p2p-media-loader') { this.player.p2pMediaLoader().on('resolutionChange', (_: any, d: any) => this.handleResolutionChange(d)) } @@ -81,6 +81,20 @@ class PeerTubePlugin extends Plugin { 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' @@ -106,10 +120,7 @@ class PeerTubePlugin extends Plugin { } dispose () { - clearTimeout(this.qualityObservationTimer) - - clearInterval(this.videoViewInterval) - + if (this.videoViewInterval) clearInterval(this.videoViewInterval) if (this.userWatchingVideoInterval) clearInterval(this.userWatchingVideoInterval) }