pub struct RoomRegistry { /* private fields */ }Expand description
Process-shared registry of live rooms. Cheap to clone (it is an Arc bag) so
it can live in ServerState and be reached from handlers and append_message.
Implementations§
Source§impl RoomRegistry
impl RoomRegistry
Sourcepub fn with_config(config: RoomConfig) -> Self
pub fn with_config(config: RoomConfig) -> Self
A registry with custom lifecycle tunables (used by tests for short windows).
Sourcepub fn get_or_create(&self, room_id: &str) -> RoomHandle
pub fn get_or_create(&self, room_id: &str) -> RoomHandle
Get the handle for room_id, spawning the room’s actor if it is not yet
live. Idempotent: repeated calls for the same id return clones of the same
handle (same broadcast sender + member counter) until the room hibernates.
Sourcepub fn join(
&self,
room_id: &str,
member_id: impl Into<String>,
) -> RoomMembership
pub fn join( &self, room_id: &str, member_id: impl Into<String>, ) -> RoomMembership
Join room_id as member_id, get-or-creating the room AND incrementing its
member count atomically under the registry lock. This is the race-safe
entry point that any concurrent caller (the WS gateway) must use instead of
get_or_create() followed by RoomHandle::join.
Because [try_evict] rechecks the member count under this same lock, the
increment can never be observed as zero in the gap between get-or-create and
join. So a join racing an eviction has exactly two outcomes: the join takes
the lock first (eviction then sees members > 0 and aborts, keeping the
existing room), or eviction takes it first (removes the entry and exits;
this call then transparently spawns a fresh room). Neither outcome yields an
orphaned handle whose actor is dead and whose registry entry is gone.
Sourcepub fn publish_event(&self, room_id: &str, value: Value)
pub fn publish_event(&self, room_id: &str, value: Value)
Publish an Events frame to room_id. No-op if the room is not live (no
members are subscribed, so there is nothing to deliver and no reason to
spin up an actor).
Sourcepub fn publish_presence(&self, room_id: &str, member_id: &str, value: Value)
pub fn publish_presence(&self, room_id: &str, member_id: &str, value: Value)
Publish a presence delta for member_id to room_id: stores it in the
room’s ephemeral map (so the heartbeat TTL applies) and broadcasts on the
Presence channel. No-op if the room is not live.
Sourcepub fn broadcast_event(
&self,
room_id: &str,
name: impl Into<String>,
payload: Value,
)
pub fn broadcast_event( &self, room_id: &str, name: impl Into<String>, payload: Value, )
Broadcast a typed named event to room_id (Rivet’s broadcast(event, payload)). No-op if the room is not live — the registry-level twin of
publish_event, for callers holding only the registry.
Sourcepub fn send_event(
&self,
room_id: &str,
conn: ConnId,
name: impl Into<String>,
payload: Value,
)
pub fn send_event( &self, room_id: &str, conn: ConnId, name: impl Into<String>, payload: Value, )
Deliver a typed named event to one connection in room_id (Rivet’s
conn.send(event, payload)). No-op if the room is not live or the connection
has closed.
Sourcepub fn room_count(&self) -> usize
pub fn room_count(&self) -> usize
Number of live (non-hibernated) rooms. Primarily for tests/diagnostics.
Trait Implementations§
Source§impl Clone for RoomRegistry
impl Clone for RoomRegistry
Source§fn clone(&self) -> RoomRegistry
fn clone(&self) -> RoomRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more