@bowbee/peer-lite
Version:
Lightweight WebRTC browser library that supports video, audio and data channels
58 lines (57 loc) • 2.17 kB
TypeScript
export declare type Arguments<T> = [T] extends [(...args: infer U) => any] ? U : [T] extends [void] ? [] : [T];
export interface TypedEmitter<Events> {
on<E extends keyof Events>(event: E, listener: Events[E]): this;
off<E extends keyof Events>(event: E, listener: Events[E]): this;
offAll<E extends keyof Events>(event?: E): this;
emit<E extends keyof Events>(event: E, ...args: Arguments<Events[E]>): boolean;
}
export interface PeerEvents {
error: (data: {
id: string;
message: string;
error?: Error;
}) => void;
connecting: VoidFunction;
connected: VoidFunction;
disconnected: VoidFunction;
status: (status: RTCIceConnectionState) => void;
signal: (description: RTCSessionDescriptionInit) => void;
onicecandidates: (iceCandidates: RTCIceCandidate[]) => void;
streamLocal: (stream: MediaStream) => void;
streamRemote: (stream: MediaStream) => void;
channelOpen: (data: {
channel: RTCDataChannel;
}) => void;
channelClosed: (data: {
channel: RTCDataChannel;
}) => void;
channelError: (data: {
channel: RTCDataChannel;
event: RTCErrorEvent;
}) => void;
channelData: (data: {
channel: RTCDataChannel;
source: 'incoming' | 'outgoing';
data: string | Blob | ArrayBuffer | ArrayBufferView;
}) => void;
}
export interface PeerOptions {
/** Enable support for batching ICECandidates */
batchCandidates?: boolean;
/** Timeout in MS before emitting batched ICECandidates */
batchCandidatesTimeout?: number;
/** Peer id used when emitting errors */
id?: string;
/** RTCPeerConnection options */
config?: RTCConfiguration;
/** RTCOfferOptions options */
offerOptions?: RTCOfferOptions;
/** Enable support for RTCDataChannels */
enableDataChannels?: boolean;
/** Default RTCDataChannel label */
channelLabel?: string;
/** Default RTCDataChannel options */
channelOptions?: RTCDataChannelInit;
/** Function to transform offer/answer SDP */
sdpTransform?: (sdp: string) => string;
}