From 2d056f6604ab6b5b8dd5ef35e936b89cc6fd48e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 9 Feb 2021 11:46:16 +0100 Subject: Try to recover from network errors --- .../assets/player/p2p-media-loader/hls-plugin.ts | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'client') diff --git a/client/src/assets/player/p2p-media-loader/hls-plugin.ts b/client/src/assets/player/p2p-media-loader/hls-plugin.ts index 38a940229..37242befe 100644 --- a/client/src/assets/player/p2p-media-loader/hls-plugin.ts +++ b/client/src/assets/player/p2p-media-loader/hls-plugin.ts @@ -236,6 +236,27 @@ class Html5Hlsjs { } } + private _handleNetworkError (error: any) { + if (this.errorCounts[ Hlsjs.ErrorTypes.NETWORK_ERROR] <= 5) { + console.info('trying to recover network error') + + // Wait 1 second and retry + setTimeout(() => this.hls.startLoad(), 1000) + + // Reset error count on success + this.hls.once(Hlsjs.Events.FRAG_LOADED, () => { + this.errorCounts[ Hlsjs.ErrorTypes.NETWORK_ERROR] = 0 + }) + + return + } + + console.info('bubbling network error up to VIDEOJS') + this.hls.destroy() + this.tech.error = () => error + this.tech.trigger('error') + } + private _onError (_event: any, data: Hlsjs.errorData) { const error: { message: string, code?: number } = { message: `HLS.js error: ${data.type} - fatal: ${data.fatal} - ${data.details}` @@ -249,10 +270,8 @@ class Html5Hlsjs { if (!data.fatal) return if (data.type === Hlsjs.ErrorTypes.NETWORK_ERROR) { - console.info('bubbling network error up to VIDEOJS') error.code = 2 - this.tech.error = () => error as any - this.tech.trigger('error') + this._handleNetworkError(error) } else if (data.type === Hlsjs.ErrorTypes.MEDIA_ERROR && data.details !== 'manifestIncompatibleCodecsError') { error.code = 3 this._handleMediaError(error) -- cgit v1.2.3