import WebSocket from "ws"; import { FinallyFunc } from "finally-provider"; import { Waiter } from "state-waiter"; export type WsUrl = { host: string; port: number; path: string; }; type Conf = WsUrl | { ws: WebSocket; startState: States; }; export type NodeWsDeps = Conf & { finally: FinallyFunc; onError: (error: unknown) => void; onOpen: () => void; onMessage: (message: MsgReceive) => void; onClose: () => void; }; export type States = "opening" | "running" | "stopping" | "stopped"; export type Events = "data"; export type SocketData = {}; /** * All callbacks mandatory, so they wont be forgot. * Typed callbacks, so it's convenient. * Safe callbacks, so they can throw without concern. * Callbacks in promise style. * Stringent state management. I.e. hard fail, if methods called in wrong state. * Kill functionality. Useful for also closing resource, when errors happen. */ export declare class NodeWS { private deps; ws: WebSocket; waiter: Waiter; /** * */ constructor(deps: NodeWsDeps); /** * Send a message, and wait for the first returned message. * * @tobe-deprecated Too fragile */ simpleRequest: (data: MS, timeout?: number) => Promise; /** * */ send: (data: MS) => Promise; /** * doesn't check for running state. */ private rawSend; /** * */ private onOpen; /** * */ private onMessage; /** * */ private onClose; /** * */ shutdown: () => Promise; noisyKill: () => Promise; } export {};