mirror of https://github.com/Chocobozzz/PeerTube
refactor(wt-plugin): create getVideoFile fn
parent
a5a69fc727
commit
46d992d208
|
@ -122,8 +122,15 @@ class WebTorrentPlugin extends Plugin {
|
||||||
return this.currentVideoFile ? this.currentVideoFile.resolution.id : -1
|
return this.currentVideoFile ? this.currentVideoFile.resolution.id : -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getVideoFile(): VideoFile {
|
||||||
|
const savedAverageBandwidth = getAverageBandwidthInStore()
|
||||||
|
return savedAverageBandwidth
|
||||||
|
? this.getAppropriateFile(savedAverageBandwidth)
|
||||||
|
: this.pickAverageVideoFile()
|
||||||
|
}
|
||||||
|
|
||||||
updateVideoFile (
|
updateVideoFile (
|
||||||
videoFile?: VideoFile,
|
videoFile: VideoFile,
|
||||||
options: {
|
options: {
|
||||||
forcePlay?: boolean,
|
forcePlay?: boolean,
|
||||||
seek?: number,
|
seek?: number,
|
||||||
|
@ -131,14 +138,6 @@ class WebTorrentPlugin extends Plugin {
|
||||||
} = {},
|
} = {},
|
||||||
done: () => void = () => { /* empty */ }
|
done: () => void = () => { /* empty */ }
|
||||||
) {
|
) {
|
||||||
// Automatically choose the adapted video file
|
|
||||||
if (videoFile === undefined) {
|
|
||||||
const savedAverageBandwidth = getAverageBandwidthInStore()
|
|
||||||
videoFile = savedAverageBandwidth
|
|
||||||
? this.getAppropriateFile(savedAverageBandwidth)
|
|
||||||
: this.pickAverageVideoFile()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (videoFile === undefined) {
|
if (videoFile === undefined) {
|
||||||
throw Error(`Can't update video file since videoFile is undefined.`)
|
throw Error(`Can't update video file since videoFile is undefined.`)
|
||||||
}
|
}
|
||||||
|
@ -427,7 +426,7 @@ class WebTorrentPlugin extends Plugin {
|
||||||
if (this.autoplay) {
|
if (this.autoplay) {
|
||||||
this.player.posterImage.hide()
|
this.player.posterImage.hide()
|
||||||
|
|
||||||
return this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime })
|
return this.updateVideoFile(this.getVideoFile(), { forcePlay: true, seek: this.startTime })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proxy first play
|
// Proxy first play
|
||||||
|
@ -436,7 +435,7 @@ class WebTorrentPlugin extends Plugin {
|
||||||
this.player.addClass('vjs-has-big-play-button-clicked')
|
this.player.addClass('vjs-has-big-play-button-clicked')
|
||||||
this.player.play = oldPlay
|
this.player.play = oldPlay
|
||||||
|
|
||||||
this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime })
|
this.updateVideoFile(this.getVideoFile(), { forcePlay: true, seek: this.startTime })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue