npaw-plugin-nwf
Version:
NPAW's Plugin
57 lines (56 loc) • 2.35 kB
TypeScript
import type Cdn from '../Loaders/Cdn';
/**
* @file First-chunk probe — early abort on cold-start. Mirrors Android
* `FirstChunkProbeRegistry` + `FirstChunkProbeEventListener` +
* ActiveSwitcher.evaluateFirstChunkAborts (plugin-android@video-balancer-24-2-on-main).
*
* For CDNs without EMA or peak history we apply aggressive timeouts and abort
* the call when the observed throughput cannot meet the deadline. The probe
* arms ONLY for the very first attempt to that CDN; once a peak is published
* (PR5) eligibility flips off and subsequent attempts use the normal timers.
*/
export interface FirstChunkProbeSettings {
enabled: boolean;
connectTimeoutMs: number;
totalDownloadTimeoutMs: number;
safetyFactor: number;
minSamplesBeforeAbort: number;
onlyForVideoSegments: boolean;
}
export declare const DEFAULT_FIRST_CHUNK_PROBE_SETTINGS: FirstChunkProbeSettings;
/**
* Per-call probe data. `expectedSizeBytes` starts at -1 and is filled in by
* the HEADERS_RECEIVED hook from `Content-Length`. `cancelled` flips once and
* stays — guards against double-abort.
*/
export interface FirstChunkProbeTag {
cdn: Cdn;
startMs: number;
deadlineMs: number;
expectedSizeBytes: number;
cancelled: boolean;
}
/**
* Map<XMLHttpRequest, FirstChunkProbeTag>. Mirrors Android
* `FirstChunkProbeRegistry`; the JS side does not strictly need a separate
* registry (we have direct XHR access) but keeps the data layout aligned for
* grep-ability and parity.
*/
export declare class FirstChunkProbeRegistry {
private readonly probes;
register(xhr: XMLHttpRequest, tag: FirstChunkProbeTag): void;
get(xhr: XMLHttpRequest): FirstChunkProbeTag | undefined;
unregister(xhr: XMLHttpRequest): void;
forEach(fn: (xhr: XMLHttpRequest, tag: FirstChunkProbeTag) => void): void;
size(): number;
clear(): void;
}
/**
* Eligibility for arming a first-chunk probe on this dispatch. Mirrors
* Android `firstChunkProbeForOrNull` (ProviderLoader.kt:572):
* - settings.enabled
* - settings.totalDownloadTimeoutMs > 0
* - !settings.onlyForVideoSegments OR url is a video segment
* - cdn has neither EMA nor peak bandwidth history (cold-start only)
*/
export declare function isEligibleForFirstChunkProbe(cdn: Cdn, pathname: string, settings: FirstChunkProbeSettings): boolean;