WebSocketConnection class

A wrapper around native WebSocket providing helper methods, room support, and metadata.

The WebSocketConnection is used within the Kronix framework to manage individual real-time connections, allowing for automatic JSON encoding, room management, and access to the original request Context.

Constructors

WebSocketConnection(WebSocket socket, Context context)
Creates a new connection wrapper for the given socket and context.

Properties

context Context
The Context associated with the initial HTTP upgrade request.
final
hashCode int
The hash code for this object.
no setterinherited
id String
A unique identifier for this connection, identical to the initial Context.requestId.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
socket WebSocket
The underlying native Dart WebSocket instance.
final

Methods

close([int? code, String? reason]) Future<void>
Closes the connection with an optional code and reason.
isInRoom(String room) bool
Returns true if this connection is currently in the specified room.
join(String room) → void
Joins a specific room.
leave(String room) → void
Leaves a specific room.
listen(void onData(dynamic data)?, {Function? onError, void onDone()?, bool? cancelOnError}) StreamSubscription
Sets up a listener for data events from this connection.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
send(dynamic message) → void
Sends a message to the client.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited