diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 749eb7f417b..71c0c87b815 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -96,4 +96,20 @@ declare global { // but we still need this for MatrixCall::getRidOfRTXCodecs() setCodecPreferences(codecs: RTCRtpCodecCapability[]): void; } + + interface RequestInit { + /** + * Specifies the priority of the fetch request relative to other requests of the same type. + * Must be one of the following strings: + * high: A high priority fetch request relative to other requests of the same type. + * low: A low priority fetch request relative to other requests of the same type. + * auto: Automatically determine the priority of the fetch request relative to other requests of the same type (default). + * + * @see https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attribute + * @see https://github.com/microsoft/TypeScript/issues/54472 + * @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#browser_compatibility + * Not yet supported in Safari or Firefox + */ + priority?: "high" | "low" | "auto"; + } } diff --git a/src/client.ts b/src/client.ts index a85b04f7dc2..4c27cb0f7a3 100644 --- a/src/client.ts +++ b/src/client.ts @@ -5128,6 +5128,7 @@ export class MatrixClient extends TypedEventEmitter { method: Method, url: URL | string, body?: Body, - opts: Pick = {}, + opts: Pick = {}, ): Promise> { const urlForLogs = this.sanitizeUrlForLogs(url); logger.debug(`FetchHttpApi: --> ${method} ${urlForLogs}`); @@ -276,6 +276,7 @@ export class FetchHttpApi { cache: "no-cache", credentials: "omit", // we send credentials via headers keepalive: keepAlive, + priority: opts.priority, }); logger.debug(`FetchHttpApi: <-- ${method} ${urlForLogs} [${Date.now() - start}ms ${res.status}]`); diff --git a/src/http-api/interface.ts b/src/http-api/interface.ts index ae9400f385c..57e8a18e851 100644 --- a/src/http-api/interface.ts +++ b/src/http-api/interface.ts @@ -33,7 +33,7 @@ export interface IHttpOpts { localTimeoutMs?: number; } -export interface IRequestOpts { +export interface IRequestOpts extends Pick { /** * The alternative base url to use. * If not specified, uses this.opts.baseUrl