1
0
Fork 0

Try to fix p2p-media-loader on ios

This commit is contained in:
Chocobozzz 2019-02-20 11:26:14 +01:00
parent b28e4e5e08
commit 96cb4527f1
No known key found for this signature in database
GPG key ID: 583A612D890159BE
2 changed files with 19 additions and 8 deletions

View file

@ -40,6 +40,14 @@ class P2pMediaLoaderPlugin extends Plugin {
this.options = options
if (!videojs.Html5Hlsjs) {
const message = 'HLS.js does not seem to be supported.'
console.warn(message)
player.ready(() => player.trigger('error', new Error(message)))
return
}
videojs.Html5Hlsjs.addHook('beforeinitialize', (videojsPlayer: any, hlsjs: any) => {
this.hlsjs = hlsjs
})

View file

@ -116,12 +116,8 @@ export class PeertubePlayerManager {
videojs(options.common.playerElement, videojsOptions, function (this: any) {
const player = this
player.tech_.on('error', () => {
// Fallback to webtorrent?
if (mode === 'p2p-media-loader') {
self.fallbackToWebTorrent(player, options)
}
})
player.tech_.one('error', () => self.maybeFallbackToWebTorrent(mode, player, options))
player.one('error', () => self.maybeFallbackToWebTorrent(mode, player, options))
self.addContextMenu(mode, player, options.common.embedUrl)
@ -130,12 +126,19 @@ export class PeertubePlayerManager {
})
}
private static async fallbackToWebTorrent (player: any, options: PeertubePlayerManagerOptions) {
private static async maybeFallbackToWebTorrent (currentMode: PlayerMode, player: any, options: PeertubePlayerManagerOptions) {
if (currentMode === 'webtorrent') return
console.log('Fallback to webtorrent.')
const newVideoElement = document.createElement('video')
newVideoElement.className = this.playerElementClassName
// VideoJS wraps our video element inside a div
const currentParentPlayerElement = options.common.playerElement.parentNode
let currentParentPlayerElement = options.common.playerElement.parentNode
// Fix on IOS, don't ask me why
if (!currentParentPlayerElement) currentParentPlayerElement = document.getElementById(options.common.playerElement.id).parentNode
currentParentPlayerElement.parentNode.insertBefore(newVideoElement, currentParentPlayerElement)
options.common.playerElement = newVideoElement