websocket-rpc-protocol
Version:
A JSON RPC protocol for working over websockets. Sheds the weight of JSON RPC to simplify argument names and adds features.
12 lines (11 loc) • 462 B
TypeScript
export type APIMethod = (ws: WebSocket, ...args: any[]) => any;
export interface API {
[key: string]: APIMethod | API;
}
export interface ServerAPI {
onConnect: (socket: WebSocket) => void;
onMessage: (socket: WebSocket, event: MessageEvent) => void;
send: (socket: WebSocket, data: any) => void;
push: (socket: WebSocket, data: any, forRequest?: number) => void;
}
export default function createServer(version: string, api: API): ServerAPI;