The room verbs over RoomRegistry (actions/room_registry.ts): join,
leave, send, state, watch, and unwatch, as actions a consumer mounts on a
WebSocket endpoint — the TS twin of the Rust spine's fuz_actions::room.
create_room_actions returns the handlers over the specs of
actions/room_action_specs.ts. Each is WebSocket-only — mount them on a
ws_endpoints entry, never on an RPC endpoint (a room belongs to a socket;
the Rust spine answers them method_not_found over HTTP, and a handler
reached without a connection answers the same) — actor-required, and
without side effects: the registry is memory, not the database, so no
transaction opens for a relayed message. The registry does the work and the
fan-out; this module parses, bounds, authorizes, and limits.
Seats are keyed by connection and actor: under the dispatcher's acting
selector, a leave, send, or state set acts on the acting actor's own seat,
never another actor's on the same socket.
The consumer's seams
- RoomAuthorize decides each join and watch:
{allow: false} answers
room_not_found, the same as a room that doesn't exist, so a caller
learns nothing of rooms it can't enter; `{allow: true, scope,
max_members} carries the RoomScope` the seat or watch is admitted under,
for eviction, and an optional member cap below the registry's. It gets the
caller's ids and the database, not the request's role grants: authority is
read through the database inside the reserve window (RoomAuthorize's doc). - Eviction is the consumer calling
RoomRegistry.evict after its own
authority change commits — from the handler's emit_after_commit — never
before. - Rate limits.
room_join and room_watch carry the per-account class
(rate_limit: 'account', charged by the dispatcher): each runs the
consumer's database authorizer, and one account may hold many sockets.
RoomRateLimiter is per connection, outside the account budget: it
bounds the count of joins, sends, and state sets, and the bytes of payloads
and states as each frame carries them (JSON-escaped, json_escaped_len),
because every room-wide byte lands in each member's outbound queue
(DEFAULT_WS_OUTBOUND_QUEUE_BYTES) and a member reading slower than its
room sends is closed for the overflow. A join stays on it too, since its
state and the seats it moves fan out to every member; a watch fans out
nothing, so it costs only its account charge. join_extra, a hook whose value the join answers as extra (null
without one) — for what a consumer mints per seat.
A join, step by step
The dispatcher's account charge and input parse; refuse a state over the
registry's bound; charge the connection's limiter; reserve_seat (the join
is now reachable by evictions); the authorizer; then the request's own
signal — a client cancel of the join, or its socket closing, answers
request_cancelled — and admit_seat. A join whose socket closes
mid-authorizer keeps running here, unlike the Rust one, whose request future
is dropped; its admit refuses (connection_closed, answered
request_cancelled), so it seats nothing either way. A watch runs the same
steps through the watch halves, without the connection's limiter.