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