leafx
Version:
WebSocket Client & Utilities
23 lines (20 loc) • 860 B
TypeScript
import { WebSocket } from 'ws';
declare type Client = {
id: string;
ws: WebSocket;
};
declare function subscribe(channel: string, client: Client): boolean;
declare function unsubscribe(channel: string, id: string): void;
declare function broadcastToChannel<T>(channel: string, data: T): void;
declare function sendToSubscriber<T>(channel: string, id: string, data: T): void;
declare function runForEachSubscriber(channel: string, run: (ws: WebSocket) => void): void;
declare function getSubscribersCount(channel: string): number;
declare const lobby: {
subscribe: typeof subscribe;
unsubscribe: typeof unsubscribe;
broadcastToChannel: typeof broadcastToChannel;
sendToSubscriber: typeof sendToSubscriber;
runForEachSubscriber: typeof runForEachSubscriber;
getSubscribersCount: typeof getSubscribersCount;
};
export { lobby };