import { IncomingMessage } from "http"; import { WebSocketServer } from "ws"; import { PerfectWS } from "../../PerfectWS.js"; import { WebSocketForce, WSLike } from "../../utils/WebSocketForce.js"; export type ServerHostOptions = { id?: string; password?: string | string[] | ((password: any, ws: WSLike, request?: IncomingMessage) => boolean | Promise); verbose?: boolean; debugging?: 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; wsServer?: WebSocketServer; port?: number; host?: string; /** Protocol implementation for the persistent router. Defaults to the BSON-only PerfectWS. */ perfectWSConstructor?: Constructor; /** Max concurrent connections (pending + attached). Defaults to `DEFAULT_MAX_CONNECTIONS`. */ maxConnections?: number; /** Max incoming WebSocket message size in bytes. Defaults to `DEFAULT_MAX_MESSAGE_SIZE` (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 InitializedClient = { ws: WebSocketForce; clientId: string; request?: IncomingMessage; }; type RouterFor = ReturnType['router']; export declare class ServerHost { private _options; REQUEST_TIME_OUT: number; clients: Map>; private _wsServer?; private _server; private _on; private _connectionCount; private _pendingSockets; private _passwordLimiter?; private _getRateLimitKey; constructor(_options?: ServerHostOptions); get router(): RouterFor; start(): void; private _onConnection; private _passwordValidation; private _getClientId; private _finalizeInitializeClient; /** * Initialize the client state like with methods define in the client `initializeMethods`. * This is a simple PerfectWS router - does not use the perfectWSConstructor for internal initialization. */ protected initializeClient(router: ReturnType['router'], options: InitializedClient): any | Promise; stop(): void; } export {};