Skip to content

Commit

Permalink
Fix:HLS.js retry fragments advplyr#2748 advplyr#2720
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Mar 15, 2024
1 parent 630ece8 commit 88f9533
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
10 changes: 5 additions & 5 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -36,4 +36,4 @@
"postcss": "^8.3.6",
"tailwindcss": "^3.4.1"
}
}
}
37 changes: 31 additions & 6 deletions client/players/LocalAudioPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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, () => {
Expand Down

0 comments on commit 88f9533

Please sign in to comment.