aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/webtorrent/webtorrent-plugin.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-05-12 10:32:56 +0200
committerChocobozzz <me@florianbigard.com>2020-05-12 10:32:56 +0200
commit3e2bc4ea4955ee452d742647683b9021d6b4d6d5 (patch)
treea18736a735cbbf4da2244e713c223d7def8a015c /client/src/assets/player/webtorrent/webtorrent-plugin.ts
parent1d05f9bbea70af55ba23679d2db177aefb21f2e7 (diff)
downloadPeerTube-3e2bc4ea4955ee452d742647683b9021d6b4d6d5.tar.gz
PeerTube-3e2bc4ea4955ee452d742647683b9021d6b4d6d5.tar.zst
PeerTube-3e2bc4ea4955ee452d742647683b9021d6b4d6d5.zip
Fix webtorrent play on Safari
Diffstat (limited to 'client/src/assets/player/webtorrent/webtorrent-plugin.ts')
-rw-r--r--client/src/assets/player/webtorrent/webtorrent-plugin.ts15
1 files changed, 8 insertions, 7 deletions
diff --git a/client/src/assets/player/webtorrent/webtorrent-plugin.ts b/client/src/assets/player/webtorrent/webtorrent-plugin.ts
index a894a90f5..85636c5be 100644
--- a/client/src/assets/player/webtorrent/webtorrent-plugin.ts
+++ b/client/src/assets/player/webtorrent/webtorrent-plugin.ts
@@ -2,7 +2,7 @@ import videojs from 'video.js'
2import * as WebTorrent from 'webtorrent' 2import * as WebTorrent from 'webtorrent'
3import { renderVideo } from './video-renderer' 3import { renderVideo } from './video-renderer'
4import { LoadedQualityData, PlayerNetworkInfo, WebtorrentPluginOptions } from '../peertube-videojs-typings' 4import { LoadedQualityData, PlayerNetworkInfo, WebtorrentPluginOptions } from '../peertube-videojs-typings'
5import { getRtcConfig, timeToInt, videoFileMaxByResolution, videoFileMinByResolution } from '../utils' 5import { getRtcConfig, timeToInt, videoFileMaxByResolution, videoFileMinByResolution, isIOS, isSafari } from '../utils'
6import { PeertubeChunkStore } from './peertube-chunk-store' 6import { PeertubeChunkStore } from './peertube-chunk-store'
7import { 7import {
8 getAverageBandwidthInStore, 8 getAverageBandwidthInStore,
@@ -74,7 +74,7 @@ class WebTorrentPlugin extends Plugin {
74 this.startTime = timeToInt(options.startTime) 74 this.startTime = timeToInt(options.startTime)
75 75
76 // Disable auto play on iOS 76 // Disable auto play on iOS
77 this.autoplay = options.autoplay && this.isIOS() === false 77 this.autoplay = options.autoplay && isIOS() === false
78 this.playerRefusedP2P = !getStoredP2PEnabled() 78 this.playerRefusedP2P = !getStoredP2PEnabled()
79 79
80 this.videoFiles = options.videoFiles 80 this.videoFiles = options.videoFiles
@@ -158,7 +158,7 @@ class WebTorrentPlugin extends Plugin {
158 158
159 // Don't try on iOS that does not support MediaSource 159 // Don't try on iOS that does not support MediaSource
160 // Or don't use P2P if webtorrent is disabled 160 // Or don't use P2P if webtorrent is disabled
161 if (this.isIOS() || this.playerRefusedP2P) { 161 if (isIOS() || this.playerRefusedP2P) {
162 return this.fallbackToHttp(options, () => { 162 return this.fallbackToHttp(options, () => {
163 this.player.playbackRate(oldPlaybackRate) 163 this.player.playbackRate(oldPlaybackRate)
164 return done() 164 return done()
@@ -329,6 +329,11 @@ class WebTorrentPlugin extends Plugin {
329 private tryToPlay (done?: (err?: Error) => void) { 329 private tryToPlay (done?: (err?: Error) => void) {
330 if (!done) done = function () { /* empty */ } 330 if (!done) done = function () { /* empty */ }
331 331
332 // Try in mute mode because we have issues with Safari
333 if (isSafari() && this.player.muted() === false) {
334 this.player.muted(true)
335 }
336
332 const playPromise = this.player.play() 337 const playPromise = this.player.play()
333 if (playPromise !== undefined) { 338 if (playPromise !== undefined) {
334 return playPromise.then(() => done()) 339 return playPromise.then(() => done())
@@ -543,10 +548,6 @@ class WebTorrentPlugin extends Plugin {
543 this.player.removeClass('vjs-error-display-enabled') 548 this.player.removeClass('vjs-error-display-enabled')
544 } 549 }
545 550
546 private isIOS () {
547 return !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform)
548 }
549
550 private pickAverageVideoFile () { 551 private pickAverageVideoFile () {
551 if (this.videoFiles.length === 1) return this.videoFiles[0] 552 if (this.videoFiles.length === 1) return this.videoFiles[0]
552 553