Connections
Connections represent client connections to your actor. They provide a way to handle client authentication, manage connection-specific data, and control the connection lifecycle.
Parameters
When clients connect to an actor, they can pass connection parameters that are handled during the connection process.
For example:
Connection State
The data returned from _onBeforeConnect
is used as the initial state of the connection. The connection state can be accessed in any actor method using connection.state
.
For example:
Lifecycle Hooks
See the documentation on the following lifecycle hooks:
Connection List
All active connections can be accessed with this.connections
. This is stored as Map<number, Connection>
where the key is the connection ID.
This is frequently used with conn.send(name, event)
to send messages directly to clients.
For example:
Disconnecting clients
Connections can be disconnected with:
A reason can optionally be provided like:
Offline & reconnection behavior
Clients automatically attempt to reconnect (with exponential backoff) when disconnected. Remote procedure calls made while disconnected are queued.
On reconnection, event subscriptions are reestablished & queued RPCs are executed.