Docs menu

Hub events

The realtime hub is a SignalR hub at /hub/rooms. @dotwire/client wraps it, so you only need this page if you're writing your own client or debugging the wire protocol.

Connecting

  • Transport: WebSockets only. Skip negotiation; there is no long-polling or SSE fallback.
  • Protocol: the SignalR JSON hub protocol. MessagePack isn't available.
  • Auth: pass the token as the access_token query parameter. Browsers can't set headers on a WebSocket.
  • Node role: served by All and Gateway nodes.
  • Keep-alive: the server pings every 30 seconds.
  • Token expiry: the server closes the connection when the token expires. Reconnect with a fresh token.
  • Limits: each connect spends from the read rate bucket. Each node allows Dotwire:MaxConnectionsPerUser hub plus SSE connections per user, 100 by default. Over the cap, the server closes the connection with TooManyConnections.

SignalR stateful reconnect is turned off. After a reconnect, call Subscribe again for each room and fetch missed messages with GET /rooms/{roomId}/messages?afterSeq=<last seq>. See Ordering and gap-fill.

Client-to-server methods

MethodArgumentsBehavior
SubscriberoomId (UUID)Checks the role cross-check and room membership, then joins the room. Queues a presence join. Fails with Forbidden if either check fails. With the access log on, records the live window first and fails with AccessLogUnavailable if it can't.
UnsubscriberoomIdLeaves the room and queues a presence leave.
TypingroomId, isTyping (boolean)Broadcasts a typing notification to the room. Ignored unless the connection is subscribed to the room.
SendroomId, content, idempotencyKey (string or null)Only when the server runs with Dotwire:HubSend:Enabled. Stores the message and returns { seq, time }, the same ack as REST. Fails with Forbidden unless the connection is subscribed to the room.

Membership is checked when you call Subscribe, not on each event. A revocation removes the subscription immediately, and gateways re-check every live subscription every Dotwire:MembershipSweepSeconds (60 by default) in case a revocation was lost.

Subscribe and Unsubscribe share the hub rate bucket, which is keyed per user, so all of a user's connections share one budget. Over the limit, they fail with RateLimited.

Typing has its own cooldown, per user and room across all of that user's connections: the server drops a true notification that arrives within 0.5 seconds of the last one, and drops a false notification unless the user was typing.

By default, send with POST /rooms/{roomId}/messages; see the HTTP API. With Dotwire:HubSend:Enabled, members can also call Send on a connection they already hold. It runs the same validation, presend and postsend webhooks, and idempotency rules as REST. It is authorized by the live subscription, not a per-message database query, so a role change reaches it at the next membership sweep while a revocation reaches it at once. Send and REST sends share the user's send bucket on each node. Over the limit, Send fails with RateLimited. A server without hub sends fails it with HubSendDisabled.

When the connection closes, the server queues a presence leave for every room it was subscribed to.

Server-to-client events

EventPayloadWhen
ReceiveMessage{ roomId, seq, senderId, time, content }A message was accepted in a subscribed room. Content is decrypted.
UserTyping{ roomId, userId, isTyping }A member started or stopped typing.
PresenceUpdated{ roomId, joined, left }Coalesced presence changes. joined and left are arrays of user ids.
MessageRetracted{ roomId, seq }A message was redacted. Remove it from your UI.
MessagesErased{ roomId, mode, seqs }An account erasure processed these messages. For mode delete, remove them. For anonymize, show dotwire:erased as their sender. A large erasure arrives as several events of at most 500 seqs each.
MembershipRevoked{ roomId, userId }This user was removed from the room, and the connection was unsubscribed from it.

Each event has one argument, a JSON object with camelCase fields. seq is a number. time is an ISO 8601 timestamp.

ReceiveMessage is the only event that is also stored. Typing, presence, retraction, erasure, and revocation events are ephemeral: a client that misses them doesn't get them back.

Errors

Hub method failures arrive as SignalR errors with these messages:

MessageCause
UnauthorizedThe connection's token has no sub or dw:role.
ForbiddenThe role cross-check failed, or the user isn't a member of the room.
RateLimitedThe user's hub bucket is empty, or for Send, the send bucket.
AccessLogUnavailableThe access log is on and couldn't record a Subscribe, so the subscribe was refused. Retry later.
HubSendDisabledSend was called on a server without Dotwire:HubSend:Enabled.
<code> or <code>:<reason>Send was rejected with one of the send error codes, for example presend_rejected:blocked term.

The server doesn't send detailed errors to clients.

SSE equivalents

The SSE endpoint carries the same events under lowercase names: message, typing, presence, retracted, erased, and revoked. See Stream room events.