import { EventEmitter } from 'events'; import * as http from 'http'; import { RateLimiterMemory } from 'rate-limiter-flexible'; import { WebSocket } from 'ws'; import { IBroadcaster } from './IBroadcaster.js'; import { Room } from './Room.js'; import { Session } from './Session.js'; /** * A client represents an open connection to the server */ export declare class Connection extends EventEmitter implements IBroadcaster { static readonly PING_INTERVAL_MS: number; static readonly MAX_RECEIVED_BYTES_PER_10_SEC: number; static readonly MAX_EVENTS_PER_SEC = 16; static readonly MAXIMUM_MISSED_PING = 1; static readonly CLOSE_PING_TIMEOUT = 4504; static readonly CLOSE_KICKED = 4403; static readonly ACCEPTED_EVENTS: string[]; session: Session; readonly webSocket: WebSocket; room: Room | null; /** * Handshake request object */ readonly request: http.IncomingMessage; readonly origin: string; readonly userAgent: string; readonly device: string; readonly ip: string; /** * Will close the connection if the client sends too many non-binary messages */ readonly byteRateLimiter: RateLimiterMemory; /** * Will close the connection if the client sends too many events */ readonly eventRateLimiter: RateLimiterMemory; /** * Maps message types to specific handlers */ readonly binaryMessageHandlers: { [keyCode: string]: (data: Buffer) => void; }; constructor(session: Session, webSocket: WebSocket, request: http.IncomingMessage); get closed(): boolean; /** * When a message is received on the socket */ private onMessage; /** * When the connection is closed */ private onClose; /** * Error on the websocket * @param error */ private onError; /** * Set this connection's room * @param room */ setRoom(room: Room | null): void; /** * Get current room id */ get roomId(): number | null; /** * Send en event to the websocket */ send(event: string, payload: unknown): void; sendRaw(data: Buffer | string): void; /** * Send an error to the websocket * @param error */ sendError(error: Error): void; /** * Close the underlying websocket connection */ close(code?: number, reason?: string): void; }