UNPKG

@mattkrick/fast-rtc-peer

Version:

a small RTC client for connecting 2 peers

124 lines 4.25 kB
import EventEmitter from 'eventemitter3'; import StrictEventEmitter from 'strict-event-emitter-types'; declare global { interface Window { RTCIceCandidate: typeof RTCIceCandidate; RTCPeerConnection: typeof RTCPeerConnection; RTCSessionDescription: typeof RTCSessionDescription; } interface RTCConfiguration { sdpSemantics?: 'plan-b' | 'unified-plan' | string | undefined; } interface RTCDataChannel { send(data: DataPayload): void; } interface RTCRtpTransceiver { name?: string; } } export declare type PayloadToServer = CandidatePayload | OfferPayload | AnswerPayload; export interface FastRTCPeerEvents { signal: (payload: PayloadToServer, peer: FastRTCPeer) => void; data: (data: DataPayload, peer: FastRTCPeer) => void; open: (peer: FastRTCPeer) => void; close: (peer: FastRTCPeer) => void; error: (error: Error, peer: FastRTCPeer) => void; stream: (stream: MediaStream, name: string, peer: FastRTCPeer) => void; connection: (state: RTCIceConnectionState, peer: FastRTCPeer) => void; } export declare type DataPayload = string | Blob | ArrayBuffer | ArrayBufferView; export interface PeerConfig { readonly id?: string; readonly isOfferer?: boolean; readonly userId?: string; readonly streams?: StreamDictInput; readonly wrtc?: WRTC; readonly rtcConfig?: RTCConfiguration; } export interface WRTC { RTCIceCandidate: typeof RTCIceCandidate; RTCPeerConnection: typeof RTCPeerConnection; RTCSessionDescription: typeof RTCSessionDescription; } export interface OfferPayload { readonly type: 'offer'; readonly sdp: string; } export interface CandidatePayload { readonly type: 'candidate'; readonly candidate: RTCIceCandidateInit | null; } export interface AnswerPayload { readonly type: 'answer'; readonly sdp: string; } export declare type PayloadFromServer = OfferPayload | CandidatePayload | AnswerPayload; export declare type FastRTCPeerEmitter = { new (): StrictEventEmitter<EventEmitter, FastRTCPeerEvents>; }; export declare type TrackKind = 'audio' | 'video'; interface TrackConfig { readonly track: MediaStreamTrack; readonly setParameters: (sender: RTCRtpSender) => Promise<void>; } declare type TrackConfigOrKind = TrackConfig | TrackKind; interface TrackDict { [trackName: string]: TrackConfigOrKind | null; } export interface StreamDict { [streamName: string]: TrackDict; } export interface StreamDictInput { [streamName: string]: TrackDict | MediaStream | undefined; } interface RemoteStreams { [streamName: string]: MediaStream; } declare const FastRTCPeer_base: FastRTCPeerEmitter; declare class FastRTCPeer extends FastRTCPeer_base { static defaultICEServers: Array<RTCIceServer>; static defaultConfig: { iceServers: RTCIceServer[]; sdpSemantics: string; }; static generateID: () => string; static fromStreamShorthand: (streams: StreamDictInput | undefined) => StreamDict; private readonly dataChannelQueue; private readonly isOfferer; private readonly wrtc; readonly remoteStreams: RemoteStreams; private readonly streamConfig; private readonly midsWithoutNames; private readonly pendingTransceivers; private negotiationCount; private midLookup; private dataChannel; readonly id: string; readonly peerConnection: RTCPeerConnection; userId: string | null; constructor(userConfig?: PeerConfig); private setupPeer; private onIceCandidate; private onIceConnectionStateChange; private onNegotiationNeeded; private addTrackToStream; private onTrack; private handleAnswer; private handleCandidate; private handleOffer; private handleInternalMessage; private sendInternal; private setChannelEvents; private addDataChannel; private setupTransceiver; private getTransceiver; private setTrack; private upsertStreamConfig; addStreams: (streams: StreamDict) => void; muteTrack(transceiverName: string): void; close(): void; send: (data: DataPayload) => void; dispatch(payload: PayloadFromServer): void; } export default FastRTCPeer; //# sourceMappingURL=FastRTCPeer.d.ts.map