aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets')
-rw-r--r--client/src/assets/player/peertube-videojs-plugin.ts47
1 files changed, 30 insertions, 17 deletions
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts
index a53a2cc69..5cebab6d9 100644
--- a/client/src/assets/player/peertube-videojs-plugin.ts
+++ b/client/src/assets/player/peertube-videojs-plugin.ts
@@ -8,15 +8,21 @@ import { isMobile, timeToInt, videoFileMaxByResolution, videoFileMinByResolution
8import * as CacheChunkStore from 'cache-chunk-store' 8import * as CacheChunkStore from 'cache-chunk-store'
9import { PeertubeChunkStore } from './peertube-chunk-store' 9import { PeertubeChunkStore } from './peertube-chunk-store'
10import { 10import {
11 getStoredWebTorrentEnabled,
12 getAverageBandwidthInStore, 11 getAverageBandwidthInStore,
13 getStoredMute, 12 getStoredMute,
14 getStoredVolume, 13 getStoredVolume,
14 getStoredWebTorrentEnabled,
15 saveAverageBandwidth, 15 saveAverageBandwidth,
16 saveMuteInStore, 16 saveMuteInStore,
17 saveVolumeInStore 17 saveVolumeInStore
18} from './peertube-player-local-storage' 18} from './peertube-player-local-storage'
19 19
20type PlayOptions = {
21 forcePlay?: boolean,
22 seek?: number,
23 delay?: number
24}
25
20const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin') 26const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin')
21class PeerTubePlugin extends Plugin { 27class PeerTubePlugin extends Plugin {
22 private readonly playerElement: HTMLVideoElement 28 private readonly playerElement: HTMLVideoElement
@@ -181,6 +187,15 @@ class PeerTubePlugin extends Plugin {
181 const previousVideoFile = this.currentVideoFile 187 const previousVideoFile = this.currentVideoFile
182 this.currentVideoFile = videoFile 188 this.currentVideoFile = videoFile
183 189
190 // Don't try on iOS that does not support MediaSource
191 // Or don't use P2P if webtorrent is disabled
192 if (this.isIOS() || this.playerRefusedP2P) {
193 return this.fallbackToHttp(options, () => {
194 this.player.playbackRate(oldPlaybackRate)
195 return done()
196 })
197 }
198
184 this.addTorrent(this.currentVideoFile.magnetUri, previousVideoFile, options, () => { 199 this.addTorrent(this.currentVideoFile.magnetUri, previousVideoFile, options, () => {
185 this.player.playbackRate(oldPlaybackRate) 200 this.player.playbackRate(oldPlaybackRate)
186 return done() 201 return done()
@@ -251,11 +266,7 @@ class PeerTubePlugin extends Plugin {
251 private addTorrent ( 266 private addTorrent (
252 magnetOrTorrentUrl: string, 267 magnetOrTorrentUrl: string,
253 previousVideoFile: VideoFile, 268 previousVideoFile: VideoFile,
254 options: { 269 options: PlayOptions,
255 forcePlay?: boolean,
256 seek?: number,
257 delay?: number
258 },
259 done: Function 270 done: Function
260 ) { 271 ) {
261 console.log('Adding ' + magnetOrTorrentUrl + '.') 272 console.log('Adding ' + magnetOrTorrentUrl + '.')
@@ -291,7 +302,7 @@ class PeerTubePlugin extends Plugin {
291 renderVideo(torrent.files[ 0 ], this.playerElement, renderVideoOptions, (err, renderer) => { 302 renderVideo(torrent.files[ 0 ], this.playerElement, renderVideoOptions, (err, renderer) => {
292 this.renderer = renderer 303 this.renderer = renderer
293 304
294 if (err || this.playerRefusedP2P) return this.fallbackToHttp(done) 305 if (err) return this.fallbackToHttp(options, done)
295 306
296 return this.tryToPlay(err => { 307 return this.tryToPlay(err => {
297 if (err) return done(err) 308 if (err) return done(err)
@@ -299,7 +310,7 @@ class PeerTubePlugin extends Plugin {
299 if (options.seek) this.seek(options.seek) 310 if (options.seek) this.seek(options.seek)
300 if (options.forcePlay === false && paused === true) this.player.pause() 311 if (options.forcePlay === false && paused === true) this.player.pause()
301 312
302 return done(err) 313 return done()
303 }) 314 })
304 }) 315 })
305 }, options.delay || 0) 316 }, options.delay || 0)
@@ -435,12 +446,6 @@ class PeerTubePlugin extends Plugin {
435 return this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime }) 446 return this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime })
436 } 447 }
437 448
438 // Don't try on iOS that does not support MediaSource
439 if (this.isIOS()) {
440 this.currentVideoFile = this.pickAverageVideoFile()
441 return this.fallbackToHttp(undefined, false)
442 }
443
444 // Proxy first play 449 // Proxy first play
445 const oldPlay = this.player.play.bind(this.player) 450 const oldPlay = this.player.play.bind(this.player)
446 this.player.play = () => { 451 this.player.play = () => {
@@ -570,7 +575,9 @@ class PeerTubePlugin extends Plugin {
570 return fetch(url, { method: 'PUT', body, headers }) 575 return fetch(url, { method: 'PUT', body, headers })
571 } 576 }
572 577
573 private fallbackToHttp (done?: Function, play = true) { 578 private fallbackToHttp (options: PlayOptions, done?: Function) {
579 const paused = this.player.paused()
580
574 this.disableAutoResolution(true) 581 this.disableAutoResolution(true)
575 582
576 this.flushVideoFile(this.currentVideoFile, true) 583 this.flushVideoFile(this.currentVideoFile, true)
@@ -582,9 +589,15 @@ class PeerTubePlugin extends Plugin {
582 const httpUrl = this.currentVideoFile.fileUrl 589 const httpUrl = this.currentVideoFile.fileUrl
583 this.player.src = this.savePlayerSrcFunction 590 this.player.src = this.savePlayerSrcFunction
584 this.player.src(httpUrl) 591 this.player.src(httpUrl)
585 if (play) this.tryToPlay()
586 592
587 if (done) return done() 593 return this.tryToPlay(err => {
594 if (err && done) return done(err)
595
596 if (options.seek) this.seek(options.seek)
597 if (options.forcePlay === false && paused === true) this.player.pause()
598
599 if (done) return done()
600 })
588 } 601 }
589 602
590 private handleError (err: Error | string) { 603 private handleError (err: Error | string) {