aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets/player')
-rw-r--r--client/src/assets/player/peertube-videojs-plugin.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts
index e4fea0991..057bc4b2a 100644
--- a/client/src/assets/player/peertube-videojs-plugin.ts
+++ b/client/src/assets/player/peertube-videojs-plugin.ts
@@ -185,6 +185,7 @@ class PeerTubePlugin extends Plugin {
185 console.log('Adding ' + magnetOrTorrentUrl + '.') 185 console.log('Adding ' + magnetOrTorrentUrl + '.')
186 186
187 const oldTorrent = this.torrent 187 const oldTorrent = this.torrent
188 let fakeRenderer
188 const torrentOptions = { 189 const torrentOptions = {
189 store: (chunkLength, storeOpts) => new CacheChunkStore(new PeertubeChunkStore(chunkLength, storeOpts), { 190 store: (chunkLength, storeOpts) => new CacheChunkStore(new PeertubeChunkStore(chunkLength, storeOpts), {
190 max: 100 191 max: 100
@@ -199,10 +200,37 @@ class PeerTubePlugin extends Plugin {
199 oldTorrent.pause() 200 oldTorrent.pause()
200 // Pause does not remove actual peers (in particular the webseed peer) 201 // Pause does not remove actual peers (in particular the webseed peer)
201 oldTorrent.removePeer(oldTorrent['ws']) 202 oldTorrent.removePeer(oldTorrent['ws'])
203
204 // We use a fake renderer so we download correct pieces of the next file
205 // This way we'll be able to
206 if (options.delay) {
207 const fakeVideoElem = document.createElement('video')
208 renderVideo(torrent.files[0], fakeVideoElem, { autoplay: false, controls: false }, (err, renderer) => {
209 fakeRenderer = renderer
210
211 if (err) {
212 console.error('Cannot render new torrent in fake video element.', err)
213 }
214
215 // Load the future file at the correct time
216 fakeVideoElem.currentTime = this.player.currentTime() + (options.delay / 2000)
217 })
218 }
202 } 219 }
203 220
204 // Render the video in a few seconds? (on resolution change for example, we wait some seconds of the new video resolution) 221 // Render the video in a few seconds? (on resolution change for example, we wait some seconds of the new video resolution)
205 this.addTorrentDelay = setTimeout(() => { 222 this.addTorrentDelay = setTimeout(() => {
223 if (fakeRenderer) {
224 if (fakeRenderer.destroy) {
225 try {
226 fakeRenderer.destroy()
227 } catch (err) {
228 console.log('Cannot destroy correctly fake renderer.', err)
229 }
230 }
231 fakeRenderer = undefined
232 }
233
206 const paused = this.player.paused() 234 const paused = this.player.paused()
207 235
208 this.flushVideoFile(previousVideoFile) 236 this.flushVideoFile(previousVideoFile)