Represents a client connection to an actor.
Manages connection-specific data and controls the connection lifecycle.
Connection(id: ConnectionId,websocket: WSContext<WebSocket>,protocolFormat: ProtocolFormat,state: ExtractActorConnState<A> | undefined,stateEnabled: boolean,)
Initializes a new instance of the Connection class.
This should only be constructed by Actor.
Protocol format used for message serialization and deserialization.
_websocket: WSContext<WebSocket>
WebSocket context for managing the connection.
id: ConnectionId
Unique identifier for the connection.
Sets the state of the connection.
Throws an error if the state is not enabled.
Gets the current state of the connection.
Throws an error if the state is not enabled.
Parses incoming WebSocket messages based on the protocol format.
_sendWebSocketMessage(message: OutgoingWebSocketMessage): void
Sends a WebSocket message to the client.
_serialize(value: unknown): OutgoingWebSocketMessage
Serializes a value into a WebSocket message based on the protocol format.
disconnect(reason?: string): void
Disconnects the client with an optional reason.