WebSocketUpgrade class final

A Result indicating that a duplex stream connection (e.g., WebSocket) has been established.

WebSocketUpgrade chatHandler(Request req) {
  return WebSocketUpgrade((webSocket) async {
    // The WebSocket is now active
    webSocket.sendText('Welcome to chat!');

    await for (final event in webSocket.events) {
      if (event is TextDataReceived) {
        // Broadcast message to all connected clients
        broadcastMessage(event.text);
      }
    }
  });
}
Inheritance

Constructors

WebSocketUpgrade(WebSocketCallback callback)

Properties

callback WebSocketCallback
The callback function provided to handle the duplex stream connection.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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