Add loader context to xhrSetup callback args

This commit is contained in:
Rob Walch
2026-04-30 16:45:28 -07:00
parent 69cc003b2e
commit a9c3e3795a
3 changed files with 14 additions and 6 deletions
+1 -1
View File
@@ -2413,7 +2413,7 @@ export type HlsConfig = {
fLoader?: FragmentLoaderConstructor;
pLoader?: PlaylistLoaderConstructor;
fetchSetup?: (context: LoaderContext, initParams: any) => Promise<Request> | Request;
xhrSetup?: (xhr: XMLHttpRequest, url: string) => Promise<void> | void;
xhrSetup?: (xhr: XMLHttpRequest, url: string, context: LoaderContext) => Promise<void> | void;
audioStreamController?: typeof AudioStreamController;
audioTrackController?: typeof AudioTrackController;
subtitleStreamController?: typeof SubtitleStreamController;
+5 -1
View File
@@ -322,7 +322,11 @@ export type HlsConfig = {
context: LoaderContext,
initParams: any,
) => Promise<Request> | Request;
xhrSetup?: (xhr: XMLHttpRequest, url: string) => Promise<void> | void;
xhrSetup?: (
xhr: XMLHttpRequest,
url: string,
context: LoaderContext,
) => Promise<void> | void;
// Alt Audio
audioStreamController?: typeof AudioStreamController;
+8 -4
View File
@@ -12,13 +12,17 @@ const AGE_HEADER_LINE_REGEX = /^age:\s*[\d.]+\s*$/im;
class XhrLoader extends BaseLoader {
private xhrSetup:
| ((xhr: XMLHttpRequest, url: string) => Promise<void> | void)
| ((
xhr: XMLHttpRequest,
url: string,
context: LoaderContext,
) => Promise<void> | void)
| null;
private loader: XMLHttpRequest | null = null;
constructor(config: HlsConfig) {
super();
this.xhrSetup = config ? config.xhrSetup || null : null;
this.xhrSetup = config.xhrSetup || null;
}
destroy(): void {
@@ -66,12 +70,12 @@ class XhrLoader extends BaseLoader {
Promise.resolve()
.then(() => {
if (this.loader !== xhr || this.stats.aborted) return;
return xhrSetup(xhr, context.url);
return xhrSetup.call(this, xhr, context.url, context);
})
.catch((error: Error) => {
if (this.loader !== xhr || this.stats.aborted) return;
xhr.open('GET', context.url, true);
return xhrSetup(xhr, context.url);
return xhrSetup.call(this, xhr, context.url, context);
})
.then(() => {
if (this.loader !== xhr || this.stats.aborted) return;