UNPKG

fleeta-api-lib

Version:

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

274 lines 7.85 kB
/** * WebRTC Provider * Facade Pattern: Encapsulates all WebRTC logic and provides clean API to UI components * WebRTCPlayer should ONLY access API layer through this provider */ import type { TwoWayStatus } from '../live/types'; /** * Media device capabilities interface */ export interface MediaDeviceCapabilities { microphone: { supported: boolean; available: boolean; hasPermission: boolean | null; deviceCount: number; error?: string; }; speaker: { supported: boolean; available: boolean; deviceCount: number; error?: string; }; getUserMedia: { supported: boolean; error?: string; }; } /** * Check browser media device support and availability * 브라우저의 마이크/스피커 지원 및 가용성 확인 * @returns Promise with detailed media capabilities */ export declare function checkMediaDeviceSupport(): Promise<MediaDeviceCapabilities>; /** * Request microphone permission * 마이크 권한 요청 * @returns Promise with permission result */ export declare function requestMicrophonePermission(): Promise<{ granted: boolean; stream?: MediaStream; error?: string; }>; /** * Connection state types for UI feedback */ export type ConnectionState = 'idle' | 'connecting' | 'connected' | 'disconnected' | 'failed'; /** * Connection statistics for performance monitoring */ export interface ConnectionStats { bytesReceived: number; packetsReceived: number; packetsLost: number; jitter: number; roundTripTime: number; } /** * ICE server configuration for WebRTC */ export interface ICEServer { urls: string[]; username?: string; credential?: string; } /** * WebRTC endpoints by protocol */ export interface EndpointsByProtocol { HTTPS: string; WSS: string; } /** * WebRTC Provider configuration interface */ export interface WebRTCProviderConfig { deviceId: string; channel: string; clientId?: string; role?: 'VIEWER' | 'MASTER'; enableStats?: boolean; statsInterval?: number; } /** * WebRTC Provider event callbacks interface * UI components register these to receive real-time updates */ export interface WebRTCProviderCallbacks { onStateChange?: (state: ConnectionState) => void; onError?: (error: Error) => void; onStreamReceived?: (stream: MediaStream) => void; onStatsUpdate?: (stats: ConnectionStats) => void; } /** * WebRTC Connection configuration interface */ export interface WebRTCConnectionConfig { deviceId: string; channel: string; clientId?: string; role?: 'VIEWER' | 'MASTER'; enableStats?: boolean; statsInterval?: number; provider: WebRTCProviderInterface; webrtcConfig?: InternalWebRTCConfig; onStateChange?: (state: ConnectionState) => void; onError?: (error: Error) => void; onStreamReceived?: (stream: MediaStream) => void; onStatsUpdate?: (stats: ConnectionStats) => void; } /** * WebRTC Connection events interface */ export interface WebRTCConnectionEvents { onStateChange: (state: ConnectionState) => void; onError: (error: Error) => void; onStreamReceived: (stream: MediaStream) => void; onStatsUpdate: (stats: ConnectionStats) => void; } /** * Internal WebRTC configuration (mapped from FleetA API) */ export interface InternalWebRTCConfig { region: string; channelARN: string; url: string; iceServers: ICEServer[]; endpointsByProtocol: EndpointsByProtocol; role: 'VIEWER' | 'MASTER'; clientId: string; } /** * WebRTC Provider interface for connection */ export interface WebRTCProviderInterface { getWebRTCConfig(config: any): Promise<InternalWebRTCConfig>; stopStreaming(deviceId: string): Promise<void>; changeChannel(deviceId: string, channel: string): Promise<void>; } /** * WebRTC Provider Class * 🎯 Facade Pattern: Single entry point for all WebRTC functionality * * Main provider for WebRTC live streaming functionality. * Handles SDK loading, connection management, and streaming lifecycle. */ export declare class WebRTCProvider { private config; private connection; private sdkLoader; private factory; private currentState; private currentError; private currentStats; private callbacks; /** * Create WebRTC Provider instance * @param config - Provider configuration */ constructor(config: WebRTCProviderConfig); /** * Register event callbacks for UI updates * @param callbacks - Event callback functions */ setCallbacks(callbacks: WebRTCProviderCallbacks): void; /** * Connect to live stream * Main API method - encapsulates entire connection workflow */ connect(): Promise<void>; /** * Disconnect from live stream * Main API method - handles cleanup and API calls */ disconnect(): Promise<void>; /** * Change camera channel * Main API method - handles FleetA API call * @param channel - New channel to switch to */ changeChannel(channel: string): Promise<void>; /** * Get current connection state * API method for state queries */ getState(): ConnectionState; /** * Get current connection statistics * API method for statistics queries */ getStats(): ConnectionStats | null; /** * Get current error * API method for error queries */ getError(): Error | null; /** * Get current local audio stream * API method to access local audio stream for monitoring */ getLocalAudioStream(): MediaStream | null; /** * Update provider configuration * API method for configuration updates * @param newConfig - New configuration values */ updateConfig(newConfig: Partial<WebRTCProviderConfig>): void; /** * Clean up all resources * API method for cleanup */ destroy(): void; /** * Update factory dependencies (useful for testing) */ setFactoryDependencies(dependencies: Partial<import('./WebRTCFactory').WebRTCDependencies>): void; /** * Start two-way audio communication * API method to start bidirectional audio * @param deviceId - Device ID to start two-way audio * @returns Promise with two-way audio status */ startTwoWayAudio(deviceId: string): Promise<TwoWayStatus>; /** * Stop two-way audio communication * API method to stop bidirectional audio * @param deviceId - Device ID to stop two-way audio * @returns Promise with two-way audio status */ stopTwoWayAudio(deviceId: string): Promise<TwoWayStatus>; /** * Set local audio enabled/disabled (microphone mute/unmute) * API method to control microphone * @param enabled - Whether local audio should be enabled */ setLocalAudioEnabled(enabled: boolean): void; /** * Ensure WebRTC SDK is loaded */ private ensureSDKLoaded; /** * Update factory with loaded WebRTC SDK */ private updateFactoryWithLoadedSDK; /** * Get WebRTC configuration from FleetA API */ private getWebRTCConfigFromAPI; /** * Set connection state and notify UI */ private setState; /** * Set error and notify UI */ private setError; /** * Handle stream received from WebRTC connection */ private handleStreamReceived; /** * Handle statistics update from WebRTC connection */ private handleStatsUpdate; } /** * Create WebRTC Provider instance * 🎯 Factory function for UI components * @param config - Provider configuration * @returns WebRTC Provider instance */ export declare function createWebRTCProvider(config: WebRTCProviderConfig): WebRTCProvider; //# sourceMappingURL=WebRTCProvider.d.ts.map