+ private runAutoQualityScheduler () {
+ this.autoQualityInterval = setInterval(() => {
+
+ // Not initialized or in HTTP fallback
+ if (this.torrent === undefined || this.torrent === null) return
+ if (this.isAutoResolutionOn() === false) return
+ if (this.isAutoResolutionObservation === true) return
+
+ const file = this.getAppropriateFile()
+ let changeResolution = false
+ let changeResolutionDelay = 0
+
+ // Lower resolution
+ if (this.isPlayerWaiting() && file.resolution.id < this.currentVideoFile.resolution.id) {
+ console.log('Downgrading automatically the resolution to: %s', file.resolution.label)
+ changeResolution = true
+ } else if (file.resolution.id > this.currentVideoFile.resolution.id) { // Higher resolution
+ console.log('Upgrading automatically the resolution to: %s', file.resolution.label)
+ changeResolution = true
+ changeResolutionDelay = this.CONSTANTS.AUTO_QUALITY_HIGHER_RESOLUTION_DELAY
+ }
+
+ if (changeResolution === true) {
+ this.updateResolution(file.resolution.id, changeResolutionDelay)
+
+ // Wait some seconds in observation of our new resolution
+ this.isAutoResolutionObservation = true
+
+ this.qualityObservationTimer = setTimeout(() => {
+ this.isAutoResolutionObservation = false
+ }, this.CONSTANTS.AUTO_QUALITY_OBSERVATION_TIME)
+ }
+ }, this.CONSTANTS.AUTO_QUALITY_SCHEDULER)
+ }
+
+ private isPlayerWaiting () {
+ return this.player && this.player.hasClass('vjs-waiting')
+ }
+
+ private runTorrentInfoScheduler () {
+ this.torrentInfoInterval = setInterval(() => {
+ // Not initialized yet
+ if (this.torrent === undefined) return
+
+ // Http fallback
+ if (this.torrent === null) return this.trigger('torrentInfo', false)
+
+ // webtorrent.downloadSpeed because we need to take into account the potential old torrent too
+ if (webtorrent.downloadSpeed !== 0) this.downloadSpeeds.push(webtorrent.downloadSpeed)
+
+ return this.trigger('torrentInfo', {
+ downloadSpeed: this.torrent.downloadSpeed,
+ numPeers: this.torrent.numPeers,
+ uploadSpeed: this.torrent.uploadSpeed
+ })
+ }, this.CONSTANTS.INFO_SCHEDULER)
+ }
+
+ private runViewAdd () {
+ this.clearVideoViewInterval()
+
+ // After 30 seconds (or 3/4 of the video), add a view to the video
+ let minSecondsToView = 30
+
+ if (this.videoDuration < minSecondsToView) minSecondsToView = (this.videoDuration * 3) / 4
+
+ let secondsViewed = 0
+ this.videoViewInterval = setInterval(() => {
+ if (this.player && !this.player.paused()) {
+ secondsViewed += 1
+
+ if (secondsViewed > minSecondsToView) {
+ this.clearVideoViewInterval()
+
+ this.addViewToVideo().catch(err => console.error(err))
+ }