CrdtRelayRoute class

A Serverpod Route that upgrades the request and hands the socket to sessionHost, the relay (RelaySessionHost) side of the protocol.

pod.webServer.addRoute(CrdtRelayRoute(relayHost), '/relay');

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 AuthRelayRoute extends CrdtRelayRoute {
  AuthRelayRoute(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 room (document id) travels inside the hello frame, not in the URL, so one route serves every room.

Constructors

CrdtRelayRoute(RelaySessionHost sessionHost, {Duration? pingInterval, bool allowAnyOrigin = false, Set<Method> methods = const {Method.get}, String path = '/', String? host})
pingInterval is a WebSocket-level ping, which is not the protocol's own ping (Protocol.pingInterval); null keeps Relic's default. allowAnyOrigin lets a browser page on another host connect: by default a cross-origin upgrade gets a 403.

Properties

allowAnyOrigin → bool
Whether a cross-origin upgrade is accepted.
final
asHandler → Handler
Returns this HandlerObject as a Handler.
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; null for Relic's default.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sessionHost → RelaySessionHost
The host that takes the upgraded sockets.
final

Methods

call(Request req) → Future<Result>
Handles a call to this route, by extracting Session from request and forwarding to handleCall.
inherited
handleCall(Session session, Request request) → FutureOr<Result>
Handles a call to this route.
injectIn(RelicRouter router) → void
Adds this handler to the given router with Method.get and 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