@readymade/transmit
Version:
Swiss-army knife for communicating over WebRTC DataChannel, WebSocket or Touch OSC
116 lines (115 loc) • 3.19 kB
TypeScript
interface RTCConfiguration {
iceServers?: RTCIceServer[];
iceTransportPolicy?: RTCIceTransportPolicy;
bundlePolicy?: RTCBundlePolicy;
rtcpMuxPolicy?: RTCRtcpMuxPolicy;
peerIdentity?: string;
certificates?: RTCCertificate[];
iceCandidatePoolSize?: number;
}
interface RTCIceServer {
urls: string | string[];
username?: string;
credential?: string;
credentialType?: RTCIceCredentialType;
}
type RTCIceTransportPolicy = 'all' | 'relay';
type RTCBundlePolicy = 'balanced' | 'max-bundle' | 'max-compat';
type RTCRtcpMuxPolicy = 'require';
type RTCIceCredentialType = 'password' | 'oauth';
export interface TransmitterServerConfiguration {
http?: {
protocol: string;
hostname: string;
port: number;
};
ws?: {
osc?: {
protocol: string;
hostname: string;
port: number;
};
signal?: {
protocol: string;
hostname: string;
port: number;
};
announce?: {
protocol: string;
hostname: string;
port: number;
};
message?: {
protocol: string;
hostname: string;
port: number;
};
};
}
export interface TransmitterConfiguration {
id?: string;
sharedKey?: string;
channelName?: string;
onMessage?: any;
onConnect?: any;
onDisconnect?: any;
rtcConfig?: RTCConfiguration;
serverConfig?: TransmitterServerConfiguration;
}
export interface TransmitterMessage {
id: string;
type: string;
source: string;
target: string;
payload: any;
}
export declare class Transmitter {
id: string;
sharedKey: string;
name: string;
dataChannelConfig: any;
remotePeerId: any;
peerConnection: RTCPeerConnection;
hasPulse: boolean;
isOpen: boolean;
channelName: any;
dataChannel: any;
connections: Record<string, RTCPeerConnection>;
debug: boolean;
rtcConfiguration: RTCConfiguration;
config: TransmitterConfiguration;
channel: RTCDataChannel;
store: {
messages: Array<any>;
};
private ws;
constructor(config: TransmitterConfiguration);
init(): void;
sendAnnounce(): void;
onAnnounce(snapshot: any): void;
sendSignal(msg: any): void;
connect(): void;
onOffer(msg: any): void;
onAnswerSignal(msg: any): void;
onCandidateSignal(msg: any): void;
onSignal(snapshot: any): void;
onICEStateChange(): void;
onICECandidate(ev: any): void;
onDataChannelOpen(): void;
onDataChannelClosed(): void;
onWebSocketSignal(snapshot: any): void;
createMessage(data: any): string;
send(data: any): void;
sendSocketMessage(data: any): void;
sendTouchOSCMessage(address: string, data: Array<any>): void;
onMessage(message: MessageEvent): void;
onDataChannelMessage(message: any): void;
onWebSocketMessage(message: any): void;
getWebSocketAddress(config?: {
protocol: string;
hostname: string;
port: number;
}): string;
findMessagesByProperty(prop: string, value: any): Array<TransmitterMessage>;
}
export {};