+ private player: any
+ private currentVideoFile: VideoFile
+ private torrent: WebTorrent.Torrent
+ private autoResolution = true
+ private isAutoResolutionObservation = false
+
+ private videoViewInterval
+ private torrentInfoInterval
+ private autoQualityInterval
+ private addTorrentDelay
+ private qualityObservationTimer
+ private runAutoQualitySchedulerTimer
+
+ private downloadSpeeds: number[] = []
+
+ constructor (player: videojs.Player, options: PeertubePluginOptions) {
+ super(player, options)
+
+ // Fix canplay event on google chrome by disabling default videojs autoplay
+ this.autoplay = this.player.options_.autoplay
+ this.player.options_.autoplay = false
+
+ this.videoFiles = options.videoFiles
+ this.videoViewUrl = options.videoViewUrl
+ this.videoDuration = options.videoDuration
+
+ this.savePlayerSrcFunction = this.player.src
+ // Hack to "simulate" src link in video.js >= 6
+ // Without this, we can't play the video after pausing it
+ // https://github.com/videojs/video.js/blob/master/src/js/player.js#L1633
+ this.player.src = () => true
+
+ this.playerElement = options.playerElement
+
+ this.player.ready(() => {
+ const volume = getStoredVolume()
+ if (volume !== undefined) this.player.volume(volume)
+ const muted = getStoredMute()
+ if (muted !== undefined) this.player.muted(muted)
+
+ this.initializePlayer()
+ this.runTorrentInfoScheduler()
+ this.runViewAdd()
+
+ this.player.one('play', () => {
+ // Don't run immediately scheduler, wait some seconds the TCP connections are maid
+ this.runAutoQualitySchedulerTimer = setTimeout(() => {
+ this.runAutoQualityScheduler()
+ }, this.CONSTANTS.AUTO_QUALITY_SCHEDULER)
+ })
+ })