UNPKG

@eleven-am/transcoder

Version:

High-performance HLS transcoding library with hardware acceleration, intelligent client management, and distributed processing support for Node.js

126 lines 3.91 kB
import { TaskEither } from '@eleven-am/fp'; import { QualityService } from './qualityService'; import { AudioQualityEnum, StreamType, VideoQualityEnum } from './types'; import { ExtendedEventEmitter } from './utils'; interface ClientState { clientId: string; fileId: string; filePath: string; audioQuality?: string; videoQuality?: string; videoIndex?: number; audioIndex?: number; segment: number; } interface ClientInternalState { audioQuality: AudioQualityEnum; videoQuality: VideoQualityEnum; videoIndex: number; audioIndex: number; clientId: string; filePath: string; fileId: string; } interface ClientTrackerEvents { 'client:registered': { clientId: string; fileId: string; }; 'client:departed': { clientId: string; fileId: string; }; 'stream:requested': { streamId: string; clientId: string; priority: number; }; 'stream:idle': { streamId: string; idleTime: number; }; 'stream:abandoned': { streamId: string; }; 'session:updated': ClientInternalState; } /** * ClientTracker - Monitors client activity and manages resources * * This class tracks which clients are using which streams and ensures * that unused resources are cleaned up to optimize system resource usage. */ export declare class ClientTracker extends ExtendedEventEmitter<ClientTrackerEvents> { private readonly qualityService; private readonly inactivityCheckFrequency; private readonly unusedStreamDebounceDelay; private readonly inactivityThreshold; private readonly clients; private readonly states; private readonly clientStreamMap; private readonly streamClientMap; private readonly clientSegmentHistory; private readonly pendingUnusedStreams; private readonly maxSegmentHistorySize; private inactivityCheckInterval; private readonly clientLastAccess; private readonly streamLastAccess; constructor(qualityService: QualityService, inactivityCheckFrequency?: number, unusedStreamDebounceDelay?: number, inactivityThreshold?: number); /** * Clean up resources */ dispose(): void; /** * Register client activity * @param clientInfo Information about the client and its activity */ registerClientActivity(clientInfo: ClientState): void; /** * Get the priority for a stream request * @param clientId The ID of the client requesting the stream * @param type The type of stream (video/audio) * @param quality The quality of the stream requested * @param segmentIndex The index of the segment requested * @returns A TaskEither containing the calculated priority (higher = more important) */ getPriority(clientId: string, type: StreamType, quality: string, segmentIndex: number): TaskEither<number>; /** * Initialize the tracker */ private initialize; /** * Check for idle streams and emit events */ private checkForIdleStreams; /** * Handle debounce logic for marking a stream as unused */ private debounceStreamUnused; /** * Cancel any pending unused timer for a stream */ private cancelStreamUnusedTimer; /** * Update last access timestamps for client and stream */ private updateLastAccess; /** * Check for inactive clients and clean them up */ private checkForInactiveClients; /** * Remove a client and clean up their resources */ private removeClient; /** * Update a client's session information and emit event * @param clientId The client ID to update */ private updateClientSession; /** * Analyze client behavior based on segment access pattern */ private analyzeClientBehavior; } export {}; //# sourceMappingURL=clientTracker.d.ts.map