socket-rtc
Version:
SocketRTC is a library that combines WebRTC and WebSocket to facilitate peer-to-peer communication. It allows for real-time communication between browsers and Node.js environments using WebRTC for direct peer-to-peer connections and WebSocket for signalin
44 lines (35 loc) • 1.21 kB
TypeScript
declare module 'socketrtc' {
import { Server as HTTPServer } from 'http';
import { Server as IOServer } from 'socket.io';
import SimplePeer from 'simple-peer';
interface SocketConfig {
url?: string;
server?: HTTPServer | IOServer;
}
interface RTCConfig {
initiator?: boolean;
wrtc?: any;
[key: string]: any;
}
interface EventListener {
(data?: any): void;
}
class SocketRTC {
id: string;
socket: any;
events: { [key: string]: EventListener[] };
config: RTCConfig;
clients: { [key: string]: SimplePeer.Instance };
constructor(socketConfig: SocketConfig, id?: string, rtcconfig?: RTCConfig);
on(event: "connect" | "disconnect" | "message" | "error", listener: EventListener): void;
emit(event: "connect" | "disconnect" | "message" | "error", ...args: any[]): void;
send(data: any): void;
except(id: string): {
send: (data: any) => void;
emit: (event: string, ...args: any[]) => void;
};
private initializeServer(): void;
private initializeClient(): void;
}
export = SocketRTC;
}