UNPKG

fleeta-api-lib

Version:

A comprehensive library for fleet management applications - API, Auth, Device management

156 lines 4.42 kB
/** * Generic WebRTC Connection Manager * Handles WebRTC connection lifecycle independent of specific APIs */ import { AudioManager } from './AudioManager'; import { ConnectionStateMachine } from './ConnectionStateMachine'; import type { WebRTCDependencies } from './WebRTCFactory'; import type { ConnectionState, ConnectionStats, WebRTCConnectionEvents, WebRTCConnectionConfig, InternalWebRTCConfig as WebRTCConfig } from './WebRTCProvider'; /** * WebRTC Connection internal dependencies */ interface WebRTCConnectionDependencies { audioManager: AudioManager; stateMachine: ConnectionStateMachine; dependencies: WebRTCDependencies; } /** * Extend Window interface to include KVSWebRTC */ declare global { interface Window { KVSWebRTC: { SignalingClient: any; Role: { VIEWER: string; MASTER: string; }; }; } } /** * WebRTC connection manager class * 🔧 INTERNAL USE ONLY - Should only be accessed via WebRTCProvider */ export declare class WebRTCConnection { private config; private webrtcConfig; private provider; private connectionId; private audioManager; private stateMachine; private dependencies; private error; private peerConnection; private signalingClient; private stream; private receivedStreams; private connectionEstablished; private audioRenegotiationInProgress; private lastOfferCreationTime; private stats; private statsInterval; private eventHandlers; private rtpMonitor; private lastAudioBytesSent; private lastAudioBytesReceived; /** * Create a new WebRTC connection instance * 🔧 INTERNAL USE ONLY - Called by WebRTCProvider * @param config - Connection configuration with provider * @param internalDeps - Injected dependencies for better testability */ constructor(config: WebRTCConnectionConfig, internalDeps: WebRTCConnectionDependencies); /** * Start WebRTC connection * Executes the complete workflow: get config -> setup connection -> start streaming * Assumes WebRTC SDK is already loaded by WebRTCPlayer */ connect(): Promise<void>; /** * Disconnect WebRTC connection * Cleans up all resources and stops streaming */ disconnect(): Promise<void>; /** * Change channel * @param channel - New channel to switch to */ changeChannel(channel: string): Promise<void>; /** * Start two-way audio communication */ startTwoWayAudio(): Promise<void>; /** * Stop two-way audio communication */ stopTwoWayAudio(): Promise<void>; /** * Mute/unmute local audio */ setLocalAudioEnabled(enabled: boolean): void; getLocalAudioStream(): MediaStream | null; /** * Get remote audio stream */ getRemoteAudioStream(): MediaStream | null; /** * Get current connection state */ getState(): ConnectionState; /** * Get current WebRTC configuration */ getConfig(): WebRTCConfig | null; /** * Get current connection statistics */ getStats(): ConnectionStats | null; /** * Get current error state */ getError(): Error | null; /** * Register event handler */ on<K extends keyof WebRTCConnectionEvents>(event: K, handler: WebRTCConnectionEvents[K]): void; /** * Unregister event handler */ off<K extends keyof WebRTCConnectionEvents>(event: K, handler: WebRTCConnectionEvents[K]): void; /** * Clean up all resources */ destroy(): void; /** * Initialize WebRTC connection using KVS WebRTC SDK * @param signalingInfo - WebRTC configuration from provider */ private initializeWebRTCConnection; /** * Start connection statistics monitoring */ private startStatsMonitoring; /** * Stop connection statistics monitoring */ private stopStatsMonitoring; /** * Set error and notify handlers */ private setError; /** * Handle track event with proper context binding */ private _handleTrackEvent; /** * Start detailed RTP packet transmission monitoring */ private startRTPMonitoring; /** * Stop RTP monitoring */ private stopRTPMonitoring; } export {}; //# sourceMappingURL=WebRTCConnection.d.ts.map