WebSocketTransport class final

A PeerWire over a plain WebSocket, through net-02's relay — doc/tooling-plan.md's named fallback for whatever a WebRTC data channel could not reach: a platform it has not been wired into yet, or a network whose NAT neither side's ICE candidates got through.

Every game frame rides the relay, for as long as this transport is the one in use. Unlike a WebRTC transport, where the relay's job shrinks to signalling once the peers have found each other directly, a WebSocket connection is the data path — the relay in bin/relay.dart forwards every message for the whole life of the room, which is exactly why this is named a fallback rather than the plan.

web_socket_channel rather than dart:io's WebSocket because this half of net-02 has to compile for the web too — a browser has no dart:io, and this is meant to be the same class whether the caller is a native build or one running in a tab.

Reliable throughout: a WebSocket delivers every message once and in order, so both kinds of send go the same road.

Bytes go as a binary frame (sendBytes), and the relay forwards one as it forwards text: a message is a text frame of JSON, bytes are a binary frame, and a frame of either kind from a machine that sent bytes as base64 inside JSON is delivered as bytes all the same.

Inheritance

Constructors

WebSocketTransport(WebSocketChannel _channel)

Properties

closed → Future<String?>
Completes when the socket closes, from either end, with the reason the other end gave — the relay's, when it turned this machine away — or null when it gave none.
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
slot → int
This machine's place among the machines the wire joins, the same number on every machine: nought for whoever made a room, one for who joined it, up to one fewer than a party's size. Nought by default.
no setterinherited
state → WireState
Whether the wire carries messages. WireState.open by default.
no setteroverride

Methods

close() → Future<void>
Closes the underlying socket. Safe to call more than once.
override
deliver(PeerDelivery context) → void
Hands the context's message, arrived from its slot, to every listener: what an adapter calls for each message the connection brings. A slot left out is the other machine of two — 1 - slot; a party's wire says who.
inherited
deliverBytes(PeerBytesDelivery context) → void
Hands the context's bytes, arrived from its slot, to every byte listener: what an adapter that carries binary calls for each binary message. The slot as deliver reads it.
inherited
listen(void onMessage(Map<String, Object?> message)) → Registration
Calls onMessage for every message delivered from now on, until the returned registration is cancelled. Every listener hears every message, in the order they were added.
inherited
listenBytes(void onBytes(PeerBytes bytes)) → Registration
Calls onBytes with every byte message delivered from now on and the slot of the machine that sent it, until the returned registration is cancelled. A byte message never reaches listen's listeners, nor a JSON one these.
inherited
listenFrom(void onMessage(PeerMessage message)) → Registration
Calls onMessage with every message delivered from now on and the slot of the machine that sent it, until the returned registration is cancelled.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
send(PeerSend context) → void
Hands the context's message over for delivery; returns at once.
override
sendBytes(PeerSendBytes context) → void
Hands bytes over for delivery, as send hands a message; returns at once.
override
toString() → String
A string representation of this object.
inherited

Operators

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

Static Methods

connect(Uri uri) → Future<WebSocketTransport>
Connects to a relay room at uri — ws://host:port/room/<code>, the shape bin/relay.dart listens on — and waits for the socket to actually be open before returning, so a caller's first send is never racing the handshake.