react-device-portal
Version:
Simple WebRTC data channel for React.
32 lines (31 loc) • 1.41 kB
TypeScript
export declare abstract class Peer {
protected readonly room: string;
protected isDestroyed: boolean;
protected connection: RTCPeerConnection | null;
protected channel: RTCDataChannel | null;
protected abstract role: 'initiator' | 'responder';
protected value: {
value: string;
} | null;
protected readonly onValue: ((value: string) => void) | undefined;
protected readonly sendLastValueOnConnectAndReconnect: boolean;
protected readonly webrtcSignalingServer: string;
protected readonly iceServers: Array<RTCIceServer>;
constructor(room: string, options?: {
onValue?: (value: string) => void;
sendLastValueOnConnectAndReconnect?: boolean;
webrtcSignalingServer?: string;
iceServers?: Array<RTCIceServer>;
});
protected run(): Promise<void>;
protected abstract connect(): Promise<void>;
protected close(): void;
destroy(): void;
protected getOtherPeerRole(): "initiator" | "responder";
protected acquireIceCandidatesLoop(): Promise<void>;
protected getRemoteDescription(): Promise<RTCSessionDescriptionInit | null>;
protected setAndShareLocalDescription(description: RTCSessionDescriptionInit): Promise<void>;
protected shareNewIceCandidate(event: RTCPeerConnectionIceEvent): Promise<void>;
send(value: string): void;
protected initializeConnectionAndChannel(): void;
}