WebSocketServer class
WebSocket server implementation.
A DocumentSessionHost 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 same protocol from an HTTP server you already
have, use DocumentSessionHost directly and call
acceptConnection yourself.
- Inheritance
-
- Object
- CRDTSocketServer
- SessionHostServer<
DocumentClientSession> - DocumentSessionHost
- WebSocketServer
- Mixed-in types
Constructors
-
WebSocketServer({required Future<
HttpServer> serverFactory(), required CRDTServerRegistry serverRegistry, Compressor? compressor, MessageCodec<Message> ? messageCodec, int? maxBufferSize, List<ServerSyncPlugin> ? plugins}) - Constructor
-
WebSocketServer.test({required Future<
HttpServer> serverFactory(), required CRDTServerRegistry serverRegistry, Compressor? compressor, WebSocketServerTransformer? serverTransformer, MessageCodec<Message> ? messageCodec, int? maxBufferSize, List<ServerSyncPlugin> ? plugins}) - Constructor for testing
Properties
- 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;
0while 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
- serverRegistry → CRDTServerRegistry
-
The registry holding the documents this host serves.
no setterinherited
- serverTransformer → WebSocketServerTransformer
-
Upgrades an HttpRequest to a WebSocket.
no setteroverride
-
sessions
→ Map<
String, DocumentClientSession> -
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 setteroverride
Methods
-
acceptConnection(
TransportConnection connection, {String? sessionId}) → DocumentClientSession? -
Register
connectionas 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}) → DocumentClientSession -
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) → Future< void> -
Report a ping from a client.
inherited
-
maybeTakeAlignedSnapshot(
String documentId) → Future< void> -
Take a snapshot (and prune the confirmed history) when every client
subscribed to
documentIdhas confirmed at least the server's current state.inherited -
maybeTakeAlignedSnapshotForSession(
String sessionId) → Future< void> -
Run the snapshot coordinator for every document
sessionIdis subscribed to.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) → DocumentClientSession? -
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