From: kontrollanten <6680299+kontrollanten@users.noreply.github.com> Date: Mon, 7 Dec 2020 07:39:26 +0000 (+0100) Subject: refactor(wt-plugin): create getVideoFile fn X-Git-Tag: v3.0.0-rc.1~121 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;ds=sidebyside;h=46d992d2080c59ca607151910d9987e0b8050e9f;p=github%2FChocobozzz%2FPeerTube.git refactor(wt-plugin): create getVideoFile fn --- diff --git a/client/src/assets/player/webtorrent/webtorrent-plugin.ts b/client/src/assets/player/webtorrent/webtorrent-plugin.ts index 287358ada..4eaaf51ec 100644 --- a/client/src/assets/player/webtorrent/webtorrent-plugin.ts +++ b/client/src/assets/player/webtorrent/webtorrent-plugin.ts @@ -122,8 +122,15 @@ class WebTorrentPlugin extends Plugin { return this.currentVideoFile ? this.currentVideoFile.resolution.id : -1 } + private getVideoFile(): VideoFile { + const savedAverageBandwidth = getAverageBandwidthInStore() + return savedAverageBandwidth + ? this.getAppropriateFile(savedAverageBandwidth) + : this.pickAverageVideoFile() +} + updateVideoFile ( - videoFile?: VideoFile, + videoFile: VideoFile, options: { forcePlay?: boolean, seek?: number, @@ -131,14 +138,6 @@ class WebTorrentPlugin extends Plugin { } = {}, 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) { throw Error(`Can't update video file since videoFile is undefined.`) } @@ -427,7 +426,7 @@ class WebTorrentPlugin extends Plugin { if (this.autoplay) { 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 @@ -436,7 +435,7 @@ class WebTorrentPlugin extends Plugin { this.player.addClass('vjs-has-big-play-button-clicked') this.player.play = oldPlay - this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime }) + this.updateVideoFile(this.getVideoFile(), { forcePlay: true, seek: this.startTime }) } }