WebSocketRelayServer class

WebSocket relay server implementation.

A RelaySessionHost that owns a dart:io HttpServer: it binds on start, upgrades every WebSocket request it receives and hands the socket to the host. To serve the relay protocol from an HTTP server you already have, use RelaySessionHost directly and call acceptConnection yourself.

A relay server rebroadcasts opaque CRDT change blobs to the other clients of a room and persists them in a RelayStore, without ever interpreting CRDT data: merging is entirely a client concern. One server hosts many rooms, keyed by document id.

Inheritance
Mixed-in types

Constructors

WebSocketRelayServer({required Future<HttpServer> serverFactory(), RelayStore? store, RelayCompactionCoordinator? compaction, Compressor? compressor, MessageCodec<Message>? messageCodec, int? maxBufferSize, List<ServerSyncPlugin>? plugins})
WebSocket relay server implementation.
WebSocketRelayServer.test({required Future<HttpServer> serverFactory(), WebSocketServerTransformer? serverTransformer, RelayStore? store, RelayCompactionCoordinator? compaction, Compressor? compressor, MessageCodec<Message>? messageCodec, int? maxBufferSize, List<ServerSyncPlugin>? plugins})
WebSocket relay server implementation.

Properties

compaction → RelayCompactionCoordinator
The compaction coordinator, shared across this host's sessions.
no setterinherited
compressor → Compressor
Compressor handed to every session this host creates.
finalinherited
debugLabel → String
Name of the concrete host, used in diagnostics.
no setteroverride
hashCode → int
The hash code for this object.
no setterinherited
host → String
The server host; '' while the server is not running.
no setterinherited
isRunning → bool
Whether this host accepts sessions and does its background work.
no setterinherited
maxBufferSize → int?
Maximum outbound buffer size per client session (bytes).
finalinherited
messageCodec → MessageCodec<Message>?
Message codec handed to every session this host creates.
finalinherited
ownsTransport → bool
Whether this host owns the transport it serves on.
no setterinherited
plugins → List<ServerSyncPlugin>
The server plugins
finalinherited
port → int
The server port; 0 while the server is not running.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
serverEvents → Stream<ServerEvent>
Server events stream
no setterinherited
serverFactory → Future<HttpServer> Function()
Creates the HttpServer this host serves on.
no setteroverride
serverTransformer → WebSocketServerTransformer
Upgrades an HttpRequest to a WebSocket.
no setteroverride
sessions → Map<String, RelayClientSession>
Active sessions, by id.
no setterinherited
startedMessage → String
Message of the ServerEventType.started event.
no setteroverride
state → SessionHostState
Where this host is in its lifecycle.
no setterinherited
stoppedMessage → String
Message of the ServerEventType.stopped event.
no setterinherited
store → RelayStore
The room persistence used by this host.
no setterinherited

Methods

acceptConnection(TransportConnection connection, {String? sessionId}) → RelayClientSession?
Register connection as a new session and return it.
inherited
addServerEvent(ServerEvent event) → void
Emit a ServerEvent on serverEvents.
inherited
broadcastMessage(Message message, {List<String>? excludeClientIds}) → Future<void>
Broadcast a message to all subscribed clients
inherited
closeAllSessions() → Future<void>
Gracefully close every session.
inherited
createSession({required String id, required TransportConnection connection}) → RelayClientSession
Create the session for a newly accepted connection.
inherited
dispose() → Future<void>
Dispose the server
inherited
handleSessionClosed(String sessionId) → void
Drop a session whose event stream ended.
inherited
handleSessionError(String sessionId, dynamic error) → void
Report an error on a session's event stream.
inherited
handleSessionEvent(SessionEvent event) → FutureOr<void>
Handle a SessionEvent from one of this host's sessions.
inherited
handleSessionEventDisconnected(SessionEventGeneric event) → void
Report a disconnect and drop the session.
inherited
handleSessionEventError(SessionEventGeneric event) → void
Report a session-level error.
inherited
handleSessionEventPingReceived(SessionEventGeneric event) → FutureOr<void>
Report a ping from a client.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onDispose() → Future<void>
Release what this host holds beyond its sessions and plugins.
inherited
onRunning() → void
Runs each time this host becomes isRunning: on start, or on the first acceptConnection of a host that does not own its transport.
inherited
onStart() → Future<void>
Bring up the transport this host owns. Only called when ownsTransport.
inherited
onStarted() → Future<void>
Start serving requests. Only called when ownsTransport.
inherited
onStop() → Future<void>
Tear down the transport this host owns. Only called when ownsTransport.
inherited
sendMessageToClient(String clientId, Message message) → Future<void>
Send a message to a specific client
inherited
sessionById(String id) → RelayClientSession?
The session with id, if this host still holds it.
inherited
start() → Future<bool>
Start the server
inherited
startFailureMessage(Object error) → String
Message of the ServerEventType.error event reported when start fails.
inherited
stop() → Future<void>
Stop the server
inherited
toString() → String
A string representation of this object.
inherited

Operators

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