import * as WebTorrent from 'webtorrent'
import { renderVideo } from './video-renderer'
import { LoadedQualityData, PlayerNetworkInfo, WebtorrentPluginOptions } from '../peertube-videojs-typings'
import * as WebTorrent from 'webtorrent'
import { renderVideo } from './video-renderer'
import { LoadedQualityData, PlayerNetworkInfo, WebtorrentPluginOptions } from '../peertube-videojs-typings'
-import { getRtcConfig, timeToInt, videoFileMaxByResolution, videoFileMinByResolution } from '../utils'
+import { getRtcConfig, timeToInt, videoFileMaxByResolution, videoFileMinByResolution, isIOS, isSafari } from '../utils'
import { PeertubeChunkStore } from './peertube-chunk-store'
import {
getAverageBandwidthInStore,
import { PeertubeChunkStore } from './peertube-chunk-store'
import {
getAverageBandwidthInStore,
private readonly videoDuration: number
private readonly CONSTANTS = {
INFO_SCHEDULER: 1000, // Don't change this
private readonly videoDuration: number
private readonly CONSTANTS = {
INFO_SCHEDULER: 1000, // Don't change this
return this.fallbackToHttp(options, () => {
this.player.playbackRate(oldPlaybackRate)
return done()
return this.fallbackToHttp(options, () => {
this.player.playbackRate(oldPlaybackRate)
return done()
const playPromise = this.player.play()
if (playPromise !== undefined) {
return playPromise.then(() => done())
const playPromise = this.player.play()
if (playPromise !== undefined) {
return playPromise.then(() => done())
- if (this.videoFiles === undefined || this.videoFiles.length === 0) return undefined
- if (this.videoFiles.length === 1) return this.videoFiles[0]
+ if (this.videoFiles === undefined) return undefined
+
+ const files = this.videoFiles.filter(f => f.resolution.id !== 0)
+
+ if (files.length === 0) return undefined
+ if (files.length === 1) return files[0]
// Don't change the torrent is the play was ended
if (this.torrent && this.torrent.progress === 1 && this.player.ended()) return this.currentVideoFile
if (!averageDownloadSpeed) averageDownloadSpeed = this.getAndSaveActualDownloadSpeed()
// Don't change the torrent is the play was ended
if (this.torrent && this.torrent.progress === 1 && this.player.ended()) return this.currentVideoFile
if (!averageDownloadSpeed) averageDownloadSpeed = this.getAndSaveActualDownloadSpeed()
// Limit resolution according to player height
const playerHeight = this.playerElement.offsetHeight
// We take the first resolution just above the player height
// Example: player height is 530px, we want the 720p file instead of 480p
// Limit resolution according to player height
const playerHeight = this.playerElement.offsetHeight
// We take the first resolution just above the player height
// Example: player height is 530px, we want the 720p file instead of 480p
- let maxResolution = this.videoFiles[0].resolution.id
- for (let i = this.videoFiles.length - 1; i >= 0; i--) {
- const resolutionId = this.videoFiles[i].resolution.id
- if (resolutionId >= playerHeight) {
+ let maxResolution = files[0].resolution.id
+ for (let i = files.length - 1; i >= 0; i--) {
+ const resolutionId = files[i].resolution.id
+ if (resolutionId !== 0 && resolutionId >= playerHeight) {
maxResolution = resolutionId
break
}
}
// Filter videos we can play according to our screen resolution and bandwidth
maxResolution = resolutionId
break
}
}
// Filter videos we can play according to our screen resolution and bandwidth
- const filteredFiles = this.videoFiles
- .filter(f => f.resolution.id <= maxResolution)
- .filter(f => {
- const fileBitrate = (f.size / this.videoDuration)
- let threshold = fileBitrate
+ const filteredFiles = files.filter(f => f.resolution.id <= maxResolution)
+ .filter(f => {
+ const fileBitrate = (f.size / this.videoDuration)
+ let threshold = fileBitrate
- // If this is for a higher resolution or an initial load: add a margin
- if (!this.currentVideoFile || f.resolution.id > this.currentVideoFile.resolution.id) {
- threshold += ((fileBitrate * this.CONSTANTS.AUTO_QUALITY_THRESHOLD_PERCENT) / 100)
- }
+ // If this is for a higher resolution or an initial load: add a margin
+ if (!this.currentVideoFile || f.resolution.id > this.currentVideoFile.resolution.id) {
+ threshold += ((fileBitrate * this.CONSTANTS.AUTO_QUALITY_THRESHOLD_PERCENT) / 100)
+ }
this.player.posterImage.hide()
return this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime })
this.player.posterImage.hide()
return this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime })