diff options
author | kontrollanten <6680299+kontrollanten@users.noreply.github.com> | 2020-12-07 08:39:26 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-12-07 16:52:35 +0100 |
commit | 46d992d2080c59ca607151910d9987e0b8050e9f (patch) | |
tree | df283ead0efa575a3b7fb45b3a53a0e179c37e87 /client/src | |
parent | a5a69fc727c819b106210918b9adce30449932d6 (diff) | |
download | PeerTube-46d992d2080c59ca607151910d9987e0b8050e9f.tar.gz PeerTube-46d992d2080c59ca607151910d9987e0b8050e9f.tar.zst PeerTube-46d992d2080c59ca607151910d9987e0b8050e9f.zip |
refactor(wt-plugin): create getVideoFile fn
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/assets/player/webtorrent/webtorrent-plugin.ts | 21 |
1 files changed, 10 insertions, 11 deletions
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 { | |||
122 | return this.currentVideoFile ? this.currentVideoFile.resolution.id : -1 | 122 | return this.currentVideoFile ? this.currentVideoFile.resolution.id : -1 |
123 | } | 123 | } |
124 | 124 | ||
125 | private getVideoFile(): VideoFile { | ||
126 | const savedAverageBandwidth = getAverageBandwidthInStore() | ||
127 | return savedAverageBandwidth | ||
128 | ? this.getAppropriateFile(savedAverageBandwidth) | ||
129 | : this.pickAverageVideoFile() | ||
130 | } | ||
131 | |||
125 | updateVideoFile ( | 132 | updateVideoFile ( |
126 | videoFile?: VideoFile, | 133 | videoFile: VideoFile, |
127 | options: { | 134 | options: { |
128 | forcePlay?: boolean, | 135 | forcePlay?: boolean, |
129 | seek?: number, | 136 | seek?: number, |
@@ -131,14 +138,6 @@ class WebTorrentPlugin extends Plugin { | |||
131 | } = {}, | 138 | } = {}, |
132 | done: () => void = () => { /* empty */ } | 139 | done: () => void = () => { /* empty */ } |
133 | ) { | 140 | ) { |
134 | // Automatically choose the adapted video file | ||
135 | if (videoFile === undefined) { | ||
136 | const savedAverageBandwidth = getAverageBandwidthInStore() | ||
137 | videoFile = savedAverageBandwidth | ||
138 | ? this.getAppropriateFile(savedAverageBandwidth) | ||
139 | : this.pickAverageVideoFile() | ||
140 | } | ||
141 | |||
142 | if (videoFile === undefined) { | 141 | if (videoFile === undefined) { |
143 | throw Error(`Can't update video file since videoFile is undefined.`) | 142 | throw Error(`Can't update video file since videoFile is undefined.`) |
144 | } | 143 | } |
@@ -427,7 +426,7 @@ class WebTorrentPlugin extends Plugin { | |||
427 | if (this.autoplay) { | 426 | if (this.autoplay) { |
428 | this.player.posterImage.hide() | 427 | this.player.posterImage.hide() |
429 | 428 | ||
430 | return this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime }) | 429 | return this.updateVideoFile(this.getVideoFile(), { forcePlay: true, seek: this.startTime }) |
431 | } | 430 | } |
432 | 431 | ||
433 | // Proxy first play | 432 | // Proxy first play |
@@ -436,7 +435,7 @@ class WebTorrentPlugin extends Plugin { | |||
436 | this.player.addClass('vjs-has-big-play-button-clicked') | 435 | this.player.addClass('vjs-has-big-play-button-clicked') |
437 | this.player.play = oldPlay | 436 | this.player.play = oldPlay |
438 | 437 | ||
439 | this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime }) | 438 | this.updateVideoFile(this.getVideoFile(), { forcePlay: true, seek: this.startTime }) |
440 | } | 439 | } |
441 | } | 440 | } |
442 | 441 | ||