1
0
Fork 0

Try to recover from network errors

This commit is contained in:
Chocobozzz 2021-02-09 11:46:16 +01:00
parent 44d1f7f2e8
commit 2d056f6604
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 22 additions and 3 deletions

View File

@ -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)