X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fassets%2Fplayer%2Fwebtorrent%2Fwebtorrent-plugin.ts;h=e557fe722e3f7d81989d8d0769355fcb02548fcd;hb=d61893f7236abbed30c25b1823e6ecad93a8e8dd;hp=4eaaf51ecec01e67d862169b00e0526f3546a154;hpb=46d992d2080c59ca607151910d9987e0b8050e9f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/assets/player/webtorrent/webtorrent-plugin.ts b/client/src/assets/player/webtorrent/webtorrent-plugin.ts index 4eaaf51ec..e557fe722 100644 --- a/client/src/assets/player/webtorrent/webtorrent-plugin.ts +++ b/client/src/assets/player/webtorrent/webtorrent-plugin.ts @@ -122,15 +122,8 @@ 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, @@ -138,7 +131,15 @@ class WebTorrentPlugin extends Plugin { } = {}, done: () => void = () => { /* empty */ } ) { - if (videoFile === undefined) { + // Automatically choose the adapted video file + if (!videoFile) { + const savedAverageBandwidth = getAverageBandwidthInStore() + videoFile = savedAverageBandwidth + ? this.getAppropriateFile(savedAverageBandwidth) + : this.pickAverageVideoFile() + } + + if (!videoFile) { throw Error(`Can't update video file since videoFile is undefined.`) } @@ -248,6 +249,8 @@ class WebTorrentPlugin extends Plugin { options: PlayOptions, done: Function ) { + if (!magnetOrTorrentUrl) return this.fallbackToHttp(options, done) + console.log('Adding ' + magnetOrTorrentUrl + '.') const oldTorrent = this.torrent @@ -426,7 +429,7 @@ class WebTorrentPlugin extends Plugin { 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 @@ -435,7 +438,7 @@ class WebTorrentPlugin extends Plugin { 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 }) } }