import Interceptors from './Interceptors/Interceptors'; import ShadowXhrBridge from './ShadowXhrBridge'; import BalancerOptions from './Utils/Options'; import Emitter from './Utils/Emitter'; import { VideoSegment } from './Storage/VideoSegment'; import NpawPluginOptions from '../core/NpawPluginOptions'; import BalancerAnalytics from './video/BalancerAnalytics'; import PeakBandwidthSampler from './Utils/PeakBandwidthSampler'; import { FirstChunkProbeRegistry } from './Utils/FirstChunkProbe'; import type { BalancerProvider, ExternalProvidersOptions } from './Utils/ExternalProviders'; declare global { interface XMLHttpRequest { isAsync: boolean; __balancerConnectTimer?: ReturnType; __balancerTotalTimer?: ReturnType; /** Per-attempt call deadline armed by the balancer under transparent retry (replaces the xhr.timeout clamp). */ __balancerCallTimer?: ReturnType; /** The live shadow bridge carrying this request's current attempt, if any. */ __balancerShadowBridge?: ShadowXhrBridge; /** The caller (player) aborted this request; its status-0 completion is not a CDN failure (QA-4438). */ __balancerCancelledByCaller?: boolean; } } /** * @class * @description Core class for the p2p plugin. It includes the options, the websocket communication, * @exports CdnBalancer */ export default class CdnBalancer extends Emitter { interceptors: Interceptors; options: BalancerOptions; /** * Central peak-bandwidth sampler (PR5). One per balancer instance; tags are * registered at xhr.send and unregistered at loadend / abort. Public so * Loader.progressEM can update read counters without an extra hop. */ peakBandwidthSampler: PeakBandwidthSampler; /** * First-chunk probe registry (PR6). Holds FirstChunkProbeTag per in-flight * probe; consumed by the sampler's evaluateFirstChunkAborts on every tick. */ firstChunkProbeRegistry: FirstChunkProbeRegistry; private loader; private videoLogic?; private readonly _accountCode; private isEnabled; private defaultChunkDownloadTimeout; private isBitmovin; private isTheoplayer; private responseHeader; private allResponseHeader; private abort; private overrideMimeType; private requestHeader; private send; private open; private lastDecisionTimestamp; private apiHost; /** * Constructs CdnBalancer. * @param {string} accountCode NPAW Suite account code * @param npawPluginOptions Plugin-wide options */ constructor(accountCode: string, npawPluginOptions?: NpawPluginOptions, videoLogic?: BalancerAnalytics); /** Seconds the player has buffered ahead, for the trial deadline (see NpawPlugin.setBufferAheadProvider). */ private _bufferAheadProvider?; private _createLoader; /** Shadow bridges started by openAndSend and not yet terminated (see destroy()). */ private readonly liveBridges; openAndSend(request: XMLHttpRequest, segment: VideoSegment): void; getManifestResolutionStats(): { parseCount: number; resolveCount: number; resolveHits: number; resolveMisses: number; lookaheadHits: number; lastHitFastHits: number; lastHitForceHits: number; multiPassHits: number; subManifestAttachments: number; manifestCount: number; lookaheadSize: number; modelHits: number; fallbackCount: number; }; setExternalProviders(providers: BalancerProvider[], options?: ExternalProvidersOptions): void; updateExternalProviders(providers: BalancerProvider[], options?: ExternalProvidersOptions): void; clearExternalProviders(): void; getExternalProviders(): BalancerProvider[]; appendExternalProviders(providers: BalancerProvider[]): void; prependExternalProviders(providers: BalancerProvider[]): void; insertExternalProviders(providers: BalancerProvider[], index: number): void; setVideoLogic(videoLogic?: BalancerAnalytics): void; private readonly manifestIdentity; enable(): void; disable(): void; getIsEnabled(): boolean; isCdnBalancerSupported(): boolean; }