CrdtSyncRoute class
A Serverpod Route that upgrades the request and hands the socket to
sessionHost, the CRDT-aware (DocumentSessionHost) side of the
protocol.
pod.webServer.addRoute(CrdtSyncRoute(syncHost), '/sync');
handleCall completes the WebSocket upgrade. From then on the response is
a 101, so a client the host will not take — stopped, disposed, or a
session id already in use — is hung up on, with no status code and no
reason. To answer with one, subclass the route and refuse before calling
super.handleCall:
class AuthSyncRoute extends CrdtSyncRoute {
AuthSyncRoute(super.sessionHost);
@override
FutureOr<Result> handleCall(Session session, Request request) {
if (!session.isUserSignedIn) {
return Response.unauthorized();
}
return super.handleCall(session, request);
}
}
Serverpod closes the Session as soon as handleCall returns, before the
socket is handed over. Read what the check needs from it first.
The document id travels inside the protocol's own frames, not in the URL, so one route serves every document.
Constructors
-
CrdtSyncRoute(DocumentSessionHost sessionHost, {Duration? pingInterval, bool allowAnyOrigin = false, Set<
Method> methods = const {Method.get}, String path = '/', String? host}) -
pingIntervalis a WebSocket-level ping, which is not the protocol's own ping (Protocol.pingInterval);nullkeeps Relic's default.allowAnyOriginlets a browser page on another host connect: by default a cross-origin upgrade gets a403.
Properties
- allowAnyOrigin → bool
-
Whether a cross-origin upgrade is accepted.
final
- asHandler → Handler
-
Returns this
HandlerObjectas aHandler.no setterinherited - hashCode → int
-
The hash code for this object.
no setterinherited
- host → String?
-
The virtual host this route will respond to.
finalinherited
-
methods
→ Set<
Method> -
The methods this route will respond to, i.e. HTTP get or post.
finalinherited
- path → String
-
The suffix path this route will respond to.
finalinherited
- pingInterval → Duration?
-
The WebSocket-level ping interval;
nullfor Relic's default.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sessionHost → DocumentSessionHost
-
The host that takes the upgraded sockets.
final
Methods
-
call(
Request req) → Future< Result> -
Handles a call to this route, by extracting
Sessionfrom request and forwarding tohandleCall.inherited -
handleCall(
Session session, Request request) → FutureOr< Result> - Handles a call to this route.
-
injectIn(
RelicRouter router) → void -
Adds this handler to the given
routerwithMethod.getand path '/' Override to add differently.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited