WebSocketTransport class
A Transport over explicit WebSocket addresses — the path a browser peer
(or any peer without mDNS) uses.
Where LanTransport discovers peers by itself, a WebSocketTransport is
told where to connect: one or more ws(s):// URIs in connectTo, each
either another peer's listener or a relay (see WebSocketRelay). On native
platforms it can also accept inbound connections (listenPort); a browser
can only dial out.
One connection can carry many peers: a relay announces every client it hosts, and frames travel in addressed envelopes. A direct peer-to-peer connection is simply the two-party case of the same protocol. Frames stay end-to-end encrypted either way — a relay routes envelopes but can read neither payloads nor anything beyond the public room tag.
// A web app connecting to a household relay:
Passnote.builder(appId: 'shopping', salt: 'shopping:v1')
.transport(() => WebSocketTransport(
connectTo: [Uri.parse('wss://relay.example:9473')],
))
.open();
Dropped connections are re-dialed with exponential backoff for as long as the transport is started.
Constructors
-
WebSocketTransport({List<
Uri> connectTo = const [], int? listenPort, Duration reconnectBaseDelay = const Duration(seconds: 2), Duration reconnectMaxDelay = const Duration(seconds: 60), int maxInboundConnections = 64, Duration helloTimeout = const Duration(seconds: 10), int maxFrameBytes = 4 << 20}) -
Creates a transport that dials
connectToon start.
Properties
- boundPort → int?
-
The port the native listener is bound to, or
nullwhen not listening. Available after start; useful withlistenPort: 0.no setter -
connectTo
→ List<
Uri> -
The
ws(s)://addresses this transport dials on start.final -
events
→ Stream<
PeerEvent> -
Stream of peer connection and disconnection events.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- helloTimeout → Duration
-
How long an inbound connection may stay open without its
hello.final -
inbound
→ Stream<
InboundFrame> -
Stream of frames received from remote peers.
no setter
- listenPort → int?
-
The port to accept inbound connections on (native only).
final
- maxFrameBytes → int
-
Largest message accepted on any connection, in bytes.
final
- maxInboundConnections → int
-
Most inbound connections open at once.
final
- 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
-
send(
PeerId to, Frame frame) → Future< void> -
Sends
frameto the peer identified byto. -
start(
{required NodeId self, required String appId}) → Future< void> -
Starts the transport, advertising
selfunderappId. -
stop(
) → Future< void> - Stops the transport, closing all active connections.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited