UNPKG

@sawport/peers-caller

Version:

WebRTC multi-peer video call library with mesh architecture supporting up to 4 participants

92 lines 2.63 kB
/** * CallPeerConnection - WebRTC peer connection management using simple-peer * Handles individual peer-to-peer connections in the mesh network */ import SimplePeer from "simple-peer"; import type { PeerConnectionConfig } from "../types"; export interface PeerConnectionEvents { onSignal: (data: SimplePeer.SignalData) => void; onConnect: () => void; onData: (data: any) => void; onStream: (stream: MediaStream) => void; onTrack: (track: MediaStreamTrack, stream: MediaStream) => void; onClose: () => void; onError: (error: Error) => void; } export declare class CallPeerConnection { private peer; private config; private events; private connectionState; private isInitiator; private remoteUserId; private localStream; constructor(remoteUserId: string, config: PeerConnectionConfig, events?: Partial<PeerConnectionEvents>); /** * Create and initialize the peer connection */ createConnection(localStream?: MediaStream): Promise<void>; /** * Signal data to remote peer */ signal(data: SimplePeer.SignalData): void; /** * Add stream to the peer connection */ addStream(stream: MediaStream): void; /** * Remove stream from the peer connection */ removeStream(stream: MediaStream): void; /** * Replace a track in the peer connection (useful for screen sharing) */ replaceTrack(oldTrack: MediaStreamTrack, newTrack: MediaStreamTrack): void; /** * Send data through the data channel */ sendData(data: any): void; /** * Set bandwidth limits */ setBandwidthLimit(maxBitrate: number): Promise<void>; /** * Get connection state */ getConnectionState(): RTCPeerConnectionState; /** * Check if peer is connected */ isConnected(): boolean; /** * Get connection statistics */ getStats(): Promise<RTCStatsReport | null>; /** * Get remote user ID */ getRemoteUserId(): string; /** * Cleanup and destroy the peer connection */ destroy(): void; /** * Setup event listeners for the peer connection */ private setupPeerEventListeners; /** * Get detailed connection info for debugging */ getConnectionInfo(): { remoteUserId: string; isInitiator: boolean; connectionState: RTCPeerConnectionState; connected: boolean; hasLocalStream: boolean; localStreamTracks: { video: number; audio: number; } | null; }; } //# sourceMappingURL=CallPeerConnection.d.ts.map