npaw-plugin-nwf
Version:
NPAW's Plugin
53 lines (52 loc) • 2.37 kB
TypeScript
/**
* Scale factors applied to P2P timing calculations. All values arrive from the
* backend `/decision` response (fields `p2pFirstByteTimeoutScale/Cap` and
* `p2pFallbackBudgetScale/Cap`). A value of `0` is treated as `1.0` to make
* partial backend configs safe. Parity with iOS `TimingScaleConfig`.
*/
export type TimingScaleConfig = {
firstByteTimeoutScale: number;
firstByteTimeoutCap: number;
fallbackBudgetScale: number;
fallbackBudgetCap: number;
};
export declare function buildTimingScaleConfig(raw?: {
firstByteTimeoutScale?: number;
firstByteTimeoutCap?: number;
fallbackBudgetScale?: number;
fallbackBudgetCap?: number;
}): TimingScaleConfig;
/**
* Derived timing windows for the P2P download/upload state machine. Values are
* computed from the currently playing segment duration instead of fixed CDN
* budgets (see iOS/Android `P2PDerivedTiming.fromSegmentDuration`).
*
* - `electionWindowMs`: how long the local peer waits before committing to
* primary/backup roles on a given segment.
* - `leaderPromotionDelayMs`: delay between declaring the local claim and
* actually starting the CDN fetch as the elected leader.
* - `firstByteTimeoutMs`: if no byte arrives within this window from the
* elected peer, a fallback to CDN is triggered.
* - `idleChunkTimeoutMs`: time between consecutive chunks before the peer
* connection is considered stuck.
* - `leaderLeaseMs`: how long a peer's ACQUIRING claim is honored.
* - `fallbackBudgetMs`: total budget for the peer path before falling back
* to CDN; always >= firstByteTimeoutMs + 25 and >= leaderPromotionDelayMs + 25.
*/
export type P2PDerivedTiming = {
segmentDurationMilliseconds: number;
electionWindowMs: number;
leaderPromotionDelayMs: number;
firstByteTimeoutMs: number;
idleChunkTimeoutMs: number;
leaderLeaseMs: number;
fallbackBudgetMs: number;
};
export declare const DEFAULT_SEGMENT_DURATION_MS = 4000;
/**
* Builds a `P2PDerivedTiming` from a segment duration (milliseconds). Mirrors
* iOS `P2PDerivedTiming.fromSegmentDuration` byte-for-byte so JS peers pick
* identical timeout windows as their Android/iOS counterparts for the same
* rendition.
*/
export declare function derivedTimingFromSegmentDuration(segmentDurationMilliseconds?: number, scales?: TimingScaleConfig): P2PDerivedTiming;