import { IncomingMessage } from 'http'; import { WebSocketServer } from 'ws'; import { PerfectWS } from '../../PerfectWS.js'; import { WebSocketForce, WSLike } from '../../utils/WebSocketForce.js'; export type ClientHostOptions = { id?: string; password?: string | string[] | ((password: any, ws: WSLike, request?: IncomingMessage) => boolean | Promise); wsServer?: WebSocketServer; port?: number; host?: string; debugging?: boolean; verbose?: boolean; /** * Logs auth handshake lifecycle events (connected, rejected, disconnected, * unusual throws/closes) - the same lines `verbose` prints for these events, * without enabling verbose's full per-request tracing. Defaults to following * `debugging`; set explicitly to override that. `verbose: true` always forces * this on regardless, since these events are a subset of what verbose already logs. */ logAuthFlow?: boolean; /** Enables PureRPC. Both peers must explicitly use PerfectWSAdvanced and opt in. */ fullTrustedRPC?: boolean; /** Protocol implementation for the persistent router. Defaults to the BSON-only PerfectWS. */ perfectWSConstructor?: Constructor; /** Max concurrent connections (pending + attached). Defaults to 10_000. */ maxConnections?: number; /** Max incoming WebSocket message size in bytes. Defaults to 30MB. */ maxMessageSize?: number; /** Disabled automatically when `debugging` is true. Set to `false` to disable explicitly. */ passwordRateLimit?: false | { maxAttempts?: number; windowMs?: number; /** Defaults to `request.socket.remoteAddress`, which is the proxy's IP behind nginx/Cloudflare - override to read a trusted forwarding header (e.g. `CF-Connecting-IP`) instead. */ getClientKey?: (request?: IncomingMessage) => string | undefined; }; }; export type InitializedServer = { ws: WebSocketForce; serverId: string; request?: IncomingMessage; }; type RouterFor = ReturnType['router']; export declare class ClientHost { private _options; REQUEST_TIME_OUT: number; private readonly _client; private _wsServer?; private _lastSocket?; private _lastServerId?; private _connectionCount; private _pendingSockets; private _passwordLimiter?; private _getRateLimitKey; get serverId(): string | undefined; constructor(_options?: ClientHostOptions); get router(): RouterFor; start(): void; private _onConnection; private _passwordValidation; private _getServerId; private _finalizeInitializeServer; /** * Initialize the server state like with methods define in the server `initializeMethods`. * This is a simple PerfectWS router - does not use the perfectWSConstructor for internal initialization. */ protected initializeServer(router: ReturnType['router'], options: InitializedServer): any | Promise; stop(): void; } export {};