Fix:HLS.js retry fragments #2748 #2720

This commit is contained in:
advplyr 2024-03-15 17:10:43 -05:00
parent 630ece82ad
commit 88f9533b37
3 changed files with 38 additions and 13 deletions

View File

@ -16,7 +16,7 @@
"cron-parser": "^4.7.1",
"date-fns": "^2.25.0",
"epubjs": "^0.3.88",
"hls.js": "^1.0.7",
"hls.js": "^1.5.7",
"libarchive.js": "^1.3.0",
"nuxt": "^2.17.3",
"nuxt-socket-io": "^1.1.18",
@ -8627,9 +8627,9 @@
}
},
"node_modules/hls.js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/hls.js/-/hls.js-1.5.1.tgz",
"integrity": "sha512-SsUSlpyjOGnwBhVrVEG6vRFPU2SAJ0gUqrFdGeo7YPbOC0vuWK0TDMyp7n3QiaBC/Wkic771uqPnnVdT8/x+3Q=="
"version": "1.5.7",
"resolved": "https://registry.npmjs.org/hls.js/-/hls.js-1.5.7.tgz",
"integrity": "sha512-Hnyf7ojTBtXHeOW1/t6wCBJSiK1WpoKF9yg7juxldDx8u3iswrkPt2wbOA/1NiwU4j27DSIVoIEJRAhcdMef/A=="
},
"node_modules/hmac-drbg": {
"version": "1.0.1",
@ -16976,4 +16976,4 @@
}
}
}
}
}

View File

@ -21,7 +21,7 @@
"cron-parser": "^4.7.1",
"date-fns": "^2.25.0",
"epubjs": "^0.3.88",
"hls.js": "^1.0.7",
"hls.js": "^1.5.7",
"libarchive.js": "^1.3.0",
"nuxt": "^2.17.3",
"nuxt-socket-io": "^1.1.18",
@ -36,4 +36,4 @@
"postcss": "^8.3.6",
"tailwindcss": "^3.4.1"
}
}
}

View File

@ -139,11 +139,30 @@ export default class LocalAudioPlayer extends EventEmitter {
}
var hlsOptions = {
startPosition: this.startTime || -1
// No longer needed because token is put in a query string
// xhrSetup: (xhr) => {
// xhr.setRequestHeader('Authorization', `Bearer ${this.token}`)
// }
startPosition: this.startTime || -1,
fragLoadPolicy: {
default: {
maxTimeToFirstByteMs: 10000,
maxLoadTimeMs: 120000,
timeoutRetry: {
maxNumRetry: 4,
retryDelayMs: 0,
maxRetryDelayMs: 0,
},
errorRetry: {
maxNumRetry: 8,
retryDelayMs: 1000,
maxRetryDelayMs: 8000,
shouldRetry: (retryConfig, retryCount, isTimeout, httpStatus, retry) => {
if (httpStatus?.code === 404 && retryConfig?.maxNumRetry > retryCount) {
console.log(`[HLS] Server 404 for fragment retry ${retryCount} of ${retryConfig.maxNumRetry}`)
return true
}
return retry
}
},
}
}
}
this.hlsInstance = new Hls(hlsOptions)
@ -156,9 +175,15 @@ export default class LocalAudioPlayer extends EventEmitter {
})
this.hlsInstance.on(Hls.Events.ERROR, (e, data) => {
console.error('[HLS] Error', data.type, data.details, data)
if (data.details === Hls.ErrorDetails.BUFFER_STALLED_ERROR) {
console.error('[HLS] BUFFER STALLED ERROR')
} else if (data.details === Hls.ErrorDetails.FRAG_LOAD_ERROR) {
// Only show error if the fragment is not being retried
if (data.errorAction?.action !== 5) {
console.error('[HLS] FRAG LOAD ERROR', data)
}
} else {
console.error('[HLS] Error', data.type, data.details, data)
}
})
this.hlsInstance.on(Hls.Events.DESTROYING, () => {