Map of event names to argument tuples that this client can send to the server.
Map of event names to argument tuples that the server can send to this client.
Defaults to IncomingEvents if not specified.
Shape of the per-client mutable context bag accessible via context.
Defaults to Record<string, never> (no context) if not specified.
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.
ReadonlyoffUnregisters an event listener for given event.
ReadonlyonRegisters 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.
Add a listener for a given event.
Optionalcontext: anyReadonlyonceRegisters 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.
Add a one-time listener for a given event.
Optionalcontext: anySends a message to the client.
If the client is disconnected, behavior depends on the sendAfterDisconnect option:
"ignore" (default): silently returns undefined"throw": throws an errorThe name of the event to send.
The arguments to send with the event.
OptionalonReply: <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.
The message Ids (containing eventId and replyTo), or undefined if the message was not sent.
Whether the client's WebSocket connection is currently open and ready to send/receive messages.
Gets the count of messages that are waiting for a reply.
The underlying ws WebSocket instance for this connection.
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.
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.
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).