@phnq/message
Version:
Asynchronous, incremental messaging client and server
27 lines (26 loc) • 1.13 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
import http from 'http';
import https from 'https';
import { MessageConnection } from './MessageConnection';
export type ConnectionId = string;
type ConnectHandler<T, R, A = never> = (conn: MessageConnection<T, R, A>, upgradeRequest: http.IncomingMessage) => Promise<void>;
type DisconnectHandler<T, R, A = never> = (conn: MessageConnection<T, R, A>) => Promise<void>;
type ReceiveHandler<T, R, A = never> = (conn: MessageConnection<T, R, A>, message: T) => Promise<R | AsyncIterableIterator<R>>;
interface Config {
httpServer: http.Server | https.Server;
path?: string;
}
export declare class WebSocketMessageServer<T = unknown, R = T, A = never> {
private wss;
onConnect: ConnectHandler<T, R, A>;
onDisconnect: DisconnectHandler<T, R, A>;
onReceive: ReceiveHandler<T, R, A>;
private connectionsById;
constructor({ httpServer, path }: Config);
getConnection(id: ConnectionId): MessageConnection<T, R, A> | undefined;
get connections(): MessageConnection<T, R, A>[];
close(): Promise<void>;
private start;
}
export {};