private downloadSpeeds: number[] = []
- constructor (player: videojs.Player, options: WebtorrentPluginOptions) {
+ constructor (player: videojs.Player, options?: WebtorrentPluginOptions) {
super(player)
this.startTime = timeToInt(options.startTime)
return this.currentVideoFile ? this.currentVideoFile.resolution.id : -1
}
- private getVideoFile(): VideoFile {
- const savedAverageBandwidth = getAverageBandwidthInStore()
- return savedAverageBandwidth
- ? this.getAppropriateFile(savedAverageBandwidth)
- : this.pickAverageVideoFile()
-}
-
- private updateVideoFile (
- videoFile: VideoFile,
+ updateVideoFile (
+ videoFile?: VideoFile,
options: {
forcePlay?: boolean,
seek?: number,
} = {},
done: () => void = () => { /* empty */ }
) {
+ // Automatically choose the adapted video file
if (videoFile === undefined) {
+ const savedAverageBandwidth = getAverageBandwidthInStore()
+ videoFile = savedAverageBandwidth
+ ? this.getAppropriateFile(savedAverageBandwidth)
+ : this.pickAverageVideoFile()
+ }
+
+ if (!!videoFile) {
throw Error(`Can't update video file since videoFile is undefined.`)
}
if (this.autoplay) {
this.player.posterImage.hide()
- return this.updateVideoFile(this.getVideoFile(), { forcePlay: true, seek: this.startTime })
+ return this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime })
}
// Proxy first play
this.player.addClass('vjs-has-big-play-button-clicked')
this.player.play = oldPlay
- this.updateVideoFile(this.getVideoFile(), { forcePlay: true, seek: this.startTime })
+ this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime })
}
}