import WebSocket from "ws"; import { ISocketClient, MethodHandler, MethodHandlers, RequestContextBase, SocketTimeouts, GenericMiddleware } from "../types"; interface SocketRequest { method: string; payload: Payload; id: number; setAuthorization?: string; } interface SocketResponse { id: number; payload: Payload; error: SocketError | null; } export interface SocketMessage { request?: SocketRequest; response?: SocketResponse; } export interface SocketError { message: string; code: number; } /** * ISocket is a class that wraps a WebSocket connection and provides a simple interface for sending and receiving messages. * ISocket is initialized by both server and client and request/response is called symmetrically. * * ISocket handles has two timeout actions: * 1. Connection timeout: If the connection is not closed after a certain time, the connection is closed. * - This is useful to prevent a connection from being open indefinitely. This is mainly used in the server side since * the client side manages connection lifecycle manually. * 2. No response timeout: If the response is not received after a certain time, the request is timed out. * - This is mainly used by CLI to handle the case where the server is not responding. * * It is expected that timeouts should be relatively sorted in the order of connection timeout > request timeout > no response timeout. */ export declare class ISocket { private readonly ws; private readonly requestHandlers; private readonly globalMiddlewares; private readonly responseHandler; private peerAuthorization?; protected nxtRequestId: number; private connectionTimeout?; private logger; private timeouts?; constructor(ws: WebSocket, requestHandlers: MethodHandlers, globalMiddlewares: GenericMiddleware[], timeouts?: SocketTimeouts, logger?: { error: (message?: string) => void; }); protected handleMessage(message: SocketMessage): Promise; protected callHandler(handler: MethodHandler, params: Params, ctx: RequestContext, client: ISocketClient, next: () => Promise): Promise; request(method: string, params: Params, authorization?: string): Promise; protected respond(requestId: number, result: Result): void; protected respondError(requestId: number, error: SocketError): void; private resetConnectionTimeout; private handleConnectionTimeout; private resetNoResponseTimeout; private handleNoResponseTimeout; close(): void; } export declare function createISocketClient(socket: ISocket): ISocketClient; export {};