WebSocketClient

External Documentation

High-level wrapper for a WebSocket client connection.

Provides a typed Dart API over the underlying JS WebSocket, abstracting away JS interop details.

Constructors

WebSocketClient(JSWebSocket _ws)
Creates a new WebSocket client wrapper around the given JS WebSocket.

Properties

hashCode → int
The hash code for this object.
no setterinherited

isOpen → bool

Returns true if the connection is open and ready to communicate.
no setter

runtimeType → Type

A representation of the runtime type of the object.
no setterinherited

userId ↔ String?

Optional user identifier for this connection.
getter/setter pair

Methods

close([int code = 1000, String reason = '']) → void
Closes the WebSocket connection.

noSuchMethod(Invocation invocation) → dynamic

Invoked when a nonexistent method or property is accessed.
inherited

onClose(CloseHandler handler) → void

Registers a handler for connection close events

onError(ErrorHandler handler) → void

Registers a handler for error events

onMessage(MessageHandler handler) → void

Registers a handler for incoming messages

send(String message) → void

Sends a string message through the WebSocket.

sendJson(Map<String, Object?> data) → void

Sends a JSON-serializable map through the WebSocket as a JSON string.

toString() → String

A string representation of this object.
inherited

Operators

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