interface Natives { open: (method: string, url: string, async?: boolean) => void; send: (body?: Document | XMLHttpRequestBodyInit | null) => void; setRequestHeader: (name: string, value: string) => void; abort: () => void; } export default class ShadowXhrBridge { readonly shadow: XMLHttpRequest; private readonly original; private readonly natives; private readonly savedDescriptors; private savedGetResponseHeader; private savedGetAllResponseHeaders; private installedGetResponseHeader; private installedGetAllResponseHeaders; private started; private terminated; private restoreTimeout?; private attemptOffsetMs; /** The player's own timeout; 0 when the player set none. `original.timeout` can hold a balancer value. */ private playerTimeoutMs; /** Called when the player changes its timeout while a transparent retry is active. */ onPlayerTimeoutChange?: (timeoutMs: number, elapsedMs: number) => void; constructor(original: XMLHttpRequest, natives: Natives); /** * @param attemptTimeoutMs the shadow's own timeout for this attempt. Under transparent retry the balancer * passes what is left of the PLAYER's timeout, so a retried request still ends, as a timeout the player * sees, exactly when the player's own limit runs out (Fede 2026-09-25: their timeout is the hard limit). * @param elapsedMs time already spent on this player request by earlier attempts. * @param playerTimeoutMs the player's own timeout. The probe, the low-latency profile and the default * call timeout rewrite `xhr.timeout` before the first attempt, so that value is not the player's budget. */ start(url: string, headers?: Record, attemptTimeoutMs?: number, elapsedMs?: number, playerTimeoutMs?: number): void; /** True once the bridge has torn itself down (terminal event, abort or a failed start). */ isTerminated(): boolean; /** * Cancel the shadow WITHOUT telling the player. Used by the balancer's transparent retry: the * attempt that hit a deadline is abandoned, a new bridge starts on the next CDN, and the player * only ever sees the last attempt's terminal state. `cleanup()` runs first so `terminated` is * already set when the shadow's abort-time readystatechange / abort / loadend fire — `mirror()` * then drops them. The plain `abort()` below keeps mirroring, which is what a player-initiated * abort needs. */ abortSilently(): void; private failStart; abort(): void; private prepareOriginal; /** Keep response conversion owned by the transport that actually sends the request. */ private prepareResponseType; /** * Mirror the player's timeout onto the shadow and report changes to the retry loop. * * A transparent retry never sends the player's XHR itself. Without this accessor, a player * changing `xhr.timeout` while the shadow is in flight updates only the unsent original. The * retry loop then keeps the old deadline and may retry after the player has already requested a * timeout, which surfaces as an abort or a late segment instead of the player's timeout event. */ private prepareTimeout; private updateTimeout; private wireShadow; private mirror; private dispatch; private cleanup; } export {};