Message sending with optional reply tracking via send
Automatic cleanup of stale reply listeners
Instances are created automatically by EZEZWebsocketServer when a client connects
and are passed to your callbacks (e.g., onAuthRequest, onAuthOk, onMessage).
Per-client mutable context bag. Read and write freely to attach state to a specific client connection
(e.g., authenticated user info, subscriptions, room memberships).
Initialized from the server's defaultContext option via structuredClone, so each client starts with an
independent copy. Shape is typed via the TContext generic on EZEZWebsocketServer.
Registers an event listener for given event.
Please note that if a message is a reply and onReply function was given, then this listener will not be called.
Registers an event listener for given event, which will be called only once.
Please note that if a message is a reply and onReply function was given, then this listener will not be called.
Optional callback invoked when the client replies to this specific message.
When a reply arrives and this callback is registered, the reply bypasses any per-event on() listeners.
Returns Ids|undefined
The message Ids (containing eventId and replyTo), or undefined if the message was not sent.
Accessors
alive
getalive():boolean
Whether the client's WebSocket connection is currently open and ready to send/receive messages.
Returns boolean
awaitingRepliesCount
getawaitingRepliesCount():number
Gets the count of messages that are waiting for a reply.
Returns number
client
getclient():WebSocket
The underlying ws WebSocket instance for this connection.
Returns WebSocket
Remarks
Sending messages directly through this instance will bypass the library's serialization protocol
and will likely cause parsing errors on the receiving end. Use send instead.
connectionId
getconnectionId():number
Unique numeric identifier for this connection, auto-incremented starting from 0
across the lifetime of the server process.
Useful for logging or tracking individual clients. Note that this counter is global
and does not reset when the server restarts within the same process.
Returns number
Methods
disconnect
disconnect(code?:number,reason?:string):void
Disconnects the client from the server.
Parameters
Optionalcode: number
Optional close code (default: 1000 - normal closure)
Represents an individual client connected to the WebSocket server.
Each instance manages:
Instances are created automatically by EZEZWebsocketServer when a client connects and are passed to your callbacks (e.g.,
onAuthRequest,onAuthOk,onMessage).