Fix webtorrent disabling
This commit is contained in:
parent
ed638e5325
commit
a73115f31a
2 changed files with 30 additions and 28 deletions
|
@ -15,17 +15,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label i18n for="webTorrentEnabled">Policy regarding P2P technologies</label>
|
|
||||||
|
|
||||||
<div class="peertube-select-container">
|
|
||||||
<select id="webTorrentEnabled" formControlName="webTorrentEnabled">
|
|
||||||
<option i18n value="enable">Enable WebTorrent</option>
|
|
||||||
<option i18n value="disable">Disable WebTorrent</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<my-peertube-checkbox
|
<my-peertube-checkbox
|
||||||
inputName="webTorrentEnabled" formControlName="webTorrentEnabled"
|
inputName="webTorrentEnabled" formControlName="webTorrentEnabled"
|
||||||
i18n-labelText labelText="Use WebTorrent to exchange parts of the video with others"
|
i18n-labelText labelText="Use WebTorrent to exchange parts of the video with others"
|
||||||
|
|
|
@ -8,15 +8,21 @@ import { isMobile, timeToInt, videoFileMaxByResolution, videoFileMinByResolution
|
||||||
import * as CacheChunkStore from 'cache-chunk-store'
|
import * as CacheChunkStore from 'cache-chunk-store'
|
||||||
import { PeertubeChunkStore } from './peertube-chunk-store'
|
import { PeertubeChunkStore } from './peertube-chunk-store'
|
||||||
import {
|
import {
|
||||||
getStoredWebTorrentEnabled,
|
|
||||||
getAverageBandwidthInStore,
|
getAverageBandwidthInStore,
|
||||||
getStoredMute,
|
getStoredMute,
|
||||||
getStoredVolume,
|
getStoredVolume,
|
||||||
|
getStoredWebTorrentEnabled,
|
||||||
saveAverageBandwidth,
|
saveAverageBandwidth,
|
||||||
saveMuteInStore,
|
saveMuteInStore,
|
||||||
saveVolumeInStore
|
saveVolumeInStore
|
||||||
} from './peertube-player-local-storage'
|
} from './peertube-player-local-storage'
|
||||||
|
|
||||||
|
type PlayOptions = {
|
||||||
|
forcePlay?: boolean,
|
||||||
|
seek?: number,
|
||||||
|
delay?: number
|
||||||
|
}
|
||||||
|
|
||||||
const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin')
|
const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin')
|
||||||
class PeerTubePlugin extends Plugin {
|
class PeerTubePlugin extends Plugin {
|
||||||
private readonly playerElement: HTMLVideoElement
|
private readonly playerElement: HTMLVideoElement
|
||||||
|
@ -181,6 +187,15 @@ class PeerTubePlugin extends Plugin {
|
||||||
const previousVideoFile = this.currentVideoFile
|
const previousVideoFile = this.currentVideoFile
|
||||||
this.currentVideoFile = videoFile
|
this.currentVideoFile = videoFile
|
||||||
|
|
||||||
|
// Don't try on iOS that does not support MediaSource
|
||||||
|
// Or don't use P2P if webtorrent is disabled
|
||||||
|
if (this.isIOS() || this.playerRefusedP2P) {
|
||||||
|
return this.fallbackToHttp(options, () => {
|
||||||
|
this.player.playbackRate(oldPlaybackRate)
|
||||||
|
return done()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
this.addTorrent(this.currentVideoFile.magnetUri, previousVideoFile, options, () => {
|
this.addTorrent(this.currentVideoFile.magnetUri, previousVideoFile, options, () => {
|
||||||
this.player.playbackRate(oldPlaybackRate)
|
this.player.playbackRate(oldPlaybackRate)
|
||||||
return done()
|
return done()
|
||||||
|
@ -251,11 +266,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
private addTorrent (
|
private addTorrent (
|
||||||
magnetOrTorrentUrl: string,
|
magnetOrTorrentUrl: string,
|
||||||
previousVideoFile: VideoFile,
|
previousVideoFile: VideoFile,
|
||||||
options: {
|
options: PlayOptions,
|
||||||
forcePlay?: boolean,
|
|
||||||
seek?: number,
|
|
||||||
delay?: number
|
|
||||||
},
|
|
||||||
done: Function
|
done: Function
|
||||||
) {
|
) {
|
||||||
console.log('Adding ' + magnetOrTorrentUrl + '.')
|
console.log('Adding ' + magnetOrTorrentUrl + '.')
|
||||||
|
@ -291,7 +302,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
renderVideo(torrent.files[ 0 ], this.playerElement, renderVideoOptions, (err, renderer) => {
|
renderVideo(torrent.files[ 0 ], this.playerElement, renderVideoOptions, (err, renderer) => {
|
||||||
this.renderer = renderer
|
this.renderer = renderer
|
||||||
|
|
||||||
if (err || this.playerRefusedP2P) return this.fallbackToHttp(done)
|
if (err) return this.fallbackToHttp(options, done)
|
||||||
|
|
||||||
return this.tryToPlay(err => {
|
return this.tryToPlay(err => {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
@ -299,7 +310,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
if (options.seek) this.seek(options.seek)
|
if (options.seek) this.seek(options.seek)
|
||||||
if (options.forcePlay === false && paused === true) this.player.pause()
|
if (options.forcePlay === false && paused === true) this.player.pause()
|
||||||
|
|
||||||
return done(err)
|
return done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}, options.delay || 0)
|
}, options.delay || 0)
|
||||||
|
@ -435,12 +446,6 @@ class PeerTubePlugin extends Plugin {
|
||||||
return this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime })
|
return this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't try on iOS that does not support MediaSource
|
|
||||||
if (this.isIOS()) {
|
|
||||||
this.currentVideoFile = this.pickAverageVideoFile()
|
|
||||||
return this.fallbackToHttp(undefined, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Proxy first play
|
// Proxy first play
|
||||||
const oldPlay = this.player.play.bind(this.player)
|
const oldPlay = this.player.play.bind(this.player)
|
||||||
this.player.play = () => {
|
this.player.play = () => {
|
||||||
|
@ -570,7 +575,9 @@ class PeerTubePlugin extends Plugin {
|
||||||
return fetch(url, { method: 'PUT', body, headers })
|
return fetch(url, { method: 'PUT', body, headers })
|
||||||
}
|
}
|
||||||
|
|
||||||
private fallbackToHttp (done?: Function, play = true) {
|
private fallbackToHttp (options: PlayOptions, done?: Function) {
|
||||||
|
const paused = this.player.paused()
|
||||||
|
|
||||||
this.disableAutoResolution(true)
|
this.disableAutoResolution(true)
|
||||||
|
|
||||||
this.flushVideoFile(this.currentVideoFile, true)
|
this.flushVideoFile(this.currentVideoFile, true)
|
||||||
|
@ -582,9 +589,15 @@ class PeerTubePlugin extends Plugin {
|
||||||
const httpUrl = this.currentVideoFile.fileUrl
|
const httpUrl = this.currentVideoFile.fileUrl
|
||||||
this.player.src = this.savePlayerSrcFunction
|
this.player.src = this.savePlayerSrcFunction
|
||||||
this.player.src(httpUrl)
|
this.player.src(httpUrl)
|
||||||
if (play) this.tryToPlay()
|
|
||||||
|
|
||||||
if (done) return done()
|
return this.tryToPlay(err => {
|
||||||
|
if (err && done) return done(err)
|
||||||
|
|
||||||
|
if (options.seek) this.seek(options.seek)
|
||||||
|
if (options.forcePlay === false && paused === true) this.player.pause()
|
||||||
|
|
||||||
|
if (done) return done()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleError (err: Error | string) {
|
private handleError (err: Error | string) {
|
||||||
|
|
Loading…
Reference in a new issue