UNPKG

muweb-socket

Version:

WebSocket communication for mudb

49 lines (48 loc) 1.69 kB
import { MuSessionId, MuSocketState, MuSocketServerState, MuSocket, MuSocketSpec, MuSocketServer, MuSocketServerSpec } from 'mudb/socket'; export interface UWSSocketInterface { onmessage: (message: { data: Uint8Array | string; }) => void; onclose: () => void; send: (data: Uint8Array | string) => void; close: () => void; } export declare class MuWebSocketConnection { readonly sessionId: string; started: boolean; closed: boolean; reliableSocket: UWSSocketInterface; unreliableSockets: UWSSocketInterface[]; private _nextSocketSend; pendingMessages: (Uint8Array | string)[]; onMessage: (data: Uint8Array | string, unreliable: boolean) => void; onClose: () => void; serverClose: () => void; constructor(sessionId: string, reliableSocket: UWSSocketInterface, serverClose: () => void); addUnreliableSocket(socket: UWSSocketInterface): void; send(data: Uint8Array, unreliable: boolean): void; close(): void; } export declare class MuWebSocketClient implements MuSocket { readonly sessionId: MuSessionId; private _connection; state: MuSocketState; constructor(connection: MuWebSocketConnection); open(spec: MuSocketSpec): void; send(data: Uint8Array, unreliable?: boolean): void; close(): void; } export declare class MuWebSocketServer implements MuSocketServer { private _connections; clients: MuWebSocketClient[]; state: MuSocketServerState; private _httpServer; private _websocketServer; private _onClose; constructor(spec: { server: object; }); private _findConnection; start(spec: MuSocketServerSpec): void; close(): void; }