Fix p2p media loader error when reloading player

pull/6544/head
Chocobozzz 2024-08-08 12:15:18 +02:00
parent 9f57427a79
commit 691385517c
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 18 additions and 10 deletions

View File

@ -2,11 +2,11 @@ import { Events, Segment } from '@peertube/p2p-media-loader-core'
import { Engine, initHlsJsPlayer } from '@peertube/p2p-media-loader-hlsjs'
import { addQueryParams } from '@peertube/peertube-core-utils'
import { logger } from '@root-helpers/logger'
import debug from 'debug'
import Hlsjs from 'hls.js'
import videojs from 'video.js'
import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../../types'
import { SettingsButton } from '../settings/settings-menu-button'
import debug from 'debug'
const debugLogger = debug('peertube:player:p2p-media-loader')
@ -59,18 +59,26 @@ class P2pMediaLoaderPlugin extends Plugin {
return
}
player.on('hlsjs-initialized', (_: any, { hlsjs, engine }) => {
this.p2pEngine?.removeAllListeners()
this.p2pEngine?.destroy()
clearInterval(this.networkInfoInterval)
{
const onHLSJSInitialized = (_: any, { hlsjs, engine }: { hlsjs: Hlsjs, engine: Engine }) => {
this.p2pEngine?.removeAllListeners()
this.p2pEngine?.destroy()
clearInterval(this.networkInfoInterval)
this.hlsjs = hlsjs
this.p2pEngine = engine
this.hlsjs = hlsjs
this.p2pEngine = engine
debugLogger('hls.js initialized, initializing p2p-media-loader plugin', { hlsjs, engine })
debugLogger('hls.js initialized, initializing p2p-media-loader plugin', { hlsjs, engine })
player.ready(() => this.initializePlugin())
})
player.ready(() => this.initializePlugin())
}
player.on('hlsjs-initialized', onHLSJSInitialized)
this.on('dispose', () => {
this.player.off('hlsjs-initialized', onHLSJSInitialized)
})
}
player.src({
type: options.type,