UNPKG

active-switching

Version:

NPAW's SDK for CDN Balancing and P2P

82 lines (81 loc) 3 kB
import { VideoSegment } from '../Storage/VideoSegment'; import Options from '../Utils/Options'; import Cdn from './Cdn'; import Emitter from '../Utils/Emitter'; import Resource from '../Resource/Resource'; /** * @class * @description Class controlling the requests from the player to CDNs. * It has different algorithms to choose to decide which CDN has to be used for every request. * @exports CDNLoader */ export default class CDNLoader extends Emitter { private _secure?; private _method?; private _activeSwitching?; private _bandwidthThreshold; private _responseUUID?; private _options; private _cdnList; private _activeCdnRequests; private _activeRequests; private _failedRequests; private _chunkCount; private _highestChunkBandwidth; private _highestRenditionBandwidth; private _cdnLastInstantBandwith; private _cdnInstantBandwith; private _cdnPeakBandwidth; private _retries; private _totalDownloadedBytes; private _firstRequestTime; private _lastChunkTime; private _lastChunksLapse; private _resource; currentRenditionBandwidth: number; currentRenditionPos: number; renditionCount: number; initializated: boolean; monitoringStarted: boolean; /** * Constructs CDNLoader * @param {Options} options Options object. */ constructor(options: Options, resource: Resource); getSecure(): boolean; getActiveRequests(): Map<string, VideoSegment>; /** * For initial workflow and resets, asks to the API for the list of available * CDNs with the content we want to reproduce. * It creates the CDN list object and fills it with the CDNs received. * Also calculates the relative score. * @public */ setSettings(resp: balancerResponse, originalHost: string): void; private updateSettings; startMonitoring(): void; updateCDNStatsOnFailure(cdnName: string, segment: VideoSegment): void; removeActiveSegment(segment: VideoSegment): void; updateCDNStatsOnSuccess(segment: VideoSegment): void; getCdnList(): Map<string, Cdn>; updateProgressStats(): void; updateUrl(segment: VideoSegment, cdnName?: string): string | undefined; /** * Returns an object with the CDN data stats of the current content/view. * @returns {CdnLoaderStats} CDN info object. * @public */ getStats(): CdnLoaderStats; /** * CAUTION: if you try to disable many CDN you may break the view! * Enables/disables the use of a specific CDN. * You can get the name of the CDNs using getStats().cdn * @param {string} name Cdn name to be disabled/enabled. * @param {boolean} mode True to enable, False to disable. * @returns {boolean} True if change was applied, false if not. * @public */ changeStatusCDN(name: string, enable: boolean): boolean; setMaxBandwidth(name: string, bandwidth: number): boolean; getMaxBandwidth(cdnName: string): number; }