import { EventEmitter } from 'events'; import type { Server } from './server'; import type { WebSocketReadyState } from 'bun'; import type { RawData } from 'engine.io-parser'; import { Transport } from './transport'; import type { Context } from 'hono'; export interface EngineSocketOptions { pingInterval?: number; pingTimeout?: number; maxPayload?: number; } export interface SendOptions { compress?: boolean; } type SendCallback = (transport: Transport) => void; export declare class Socket extends EventEmitter { private data; readonly id: string; readonly ctx: Context; /** * The IP address of the client. */ readonly remoteAddress: { address: string; family: string; port: number; } | null; server: Server; transport: Transport; private writeBuffer; private packetsFn; private sentCallbackFn; private cleanupFn; private _readyState; private pingIntervalTimer; private pingTimeoutTimer; constructor(id: string, server: Server, transport: Transport, ctx: Context, data?: unknown); get readyState(): WebSocketReadyState; set readyState(state: WebSocketReadyState); /** * Get WebSocket instance (compatibility with connection.ts) */ get ws(): import("hono/ws").WSContext>>; /** * Setup transport event handlers */ private setTransport; /** * Upon transport "drain" event * * @private */ private onDrain; /** * Called upon transport considered open. * * @private */ private onOpen; /** * Handle Engine.IO packets */ private onPacket; /** * Called upon transport error. * * @param {Error} err - error object * @private */ private onError; /** * Pings client every `this.pingInterval` and expects response * within `this.pingTimeout` or closes connection. * * @private */ private schedulePing; /** * Resets ping timeout. * * @private */ private resetPingTimeout; /** * Clears listeners and timers associated with current transport. * * @private */ private clearTransport; /** * Called upon transport considered closed. * Possible reasons: `ping timeout`, `client error`, `parse error`, * `transport error`, `server close`, `transport close` */ private onClose; /** * Sends a message packet. * * @param {Object} data * @param {Object} options * @param {Function} callback * @return {Socket} for chaining */ send(data: RawData, options?: SendOptions, callback?: any): this; /** * Alias of {@link send}. * * @param data * @param options * @param callback */ write(data: RawData, options?: SendOptions, callback?: SendCallback): this; /** * Sends a packet. * * @param {String} type - packet type * @param {String} data * @param {Object} options * @param {Function} callback * * @private */ private sendPacket; /** * Attempts to flush the packets buffer. * * @private */ private flush; /** * Closes the socket and underlying transport. * Checking for packets in the write buffer and then closing transport * * @param {Boolean} discard - optional, discard the transport * @return {Socket} for chaining */ close(discard?: boolean): void; /** * Closes the underlying transport. * * @param {Boolean} discard * @private */ private closeTransport; } export {};