mirror of
https://github.com/video-dev/hls.js.git
synced 2026-05-17 13:30:38 +00:00
Add loader context to xhrSetup callback args
This commit is contained in:
@@ -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
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user