pub struct RoomHandle { /* private fields */ }Expand description
A cloneable handle to a live room: the broadcast sender for fan-out, the
command channel to the actor, and the shared member counter. Obtained from
RoomRegistry::get_or_create.
Implementations§
Source§impl RoomHandle
impl RoomHandle
Sourcepub fn subscribe(&self) -> Receiver<Frame>
pub fn subscribe(&self) -> Receiver<Frame>
Subscribe to this room’s fan-out. Multiple receivers are allowed; each sees every frame published after it subscribed.
Sourcepub fn member_count(&self) -> usize
pub fn member_count(&self) -> usize
Current member count.
Sourcepub fn join(&self, member_id: impl Into<String>) -> RoomMembership
pub fn join(&self, member_id: impl Into<String>) -> RoomMembership
Join this room as member_id, returning an RAII RoomMembership guard.
Dropping the guard leaves the room.
NOT race-safe against hibernation: the increment happens outside the
registry lock, so a room that hibernated between obtaining this handle and
this call yields an orphaned membership. Concurrent callers must use
RoomRegistry::join instead; this method is for single-threaded tests.
Sourcepub fn publish_event(&self, value: Value)
pub fn publish_event(&self, value: Value)
Publish an Events frame to this room.
Sourcepub fn publish_presence(&self, member_id: &str, value: Value)
pub fn publish_presence(&self, member_id: &str, value: Value)
Publish a presence delta for member_id (upsert + TTL + broadcast).
Sourcepub fn publish_doc_sync(&self, bytes: Vec<u8>)
pub fn publish_doc_sync(&self, bytes: Vec<u8>)
Publish an opaque DocSync (binary) frame, passed through untouched. Phase 3 CRDT updates ride this channel.
Sourcepub fn broadcast_event(&self, name: impl Into<String>, payload: Value)
pub fn broadcast_event(&self, name: impl Into<String>, payload: Value)
Broadcast a typed named event to every subscriber of this room (Rivet’s
broadcast(event, payload)). Rides the ordinary Frame::Event channel as an
envelope, so raw subscribe() receivers still get it and typed
Connections decode it into an Event.
Sourcepub fn send_event(&self, conn: ConnId, name: impl Into<String>, payload: Value)
pub fn send_event(&self, conn: ConnId, name: impl Into<String>, payload: Value)
Deliver a typed named event to exactly one connection (Rivet’s
conn.send(event, payload)). Unlike broadcast_event, this never touches
the shared broadcast, so no other connection and no raw broadcast subscriber
observes it. No-op if conn has closed or the room actor has exited.
Sourcepub fn open_connection(&self) -> Connection
pub fn open_connection(&self) -> Connection
Open a typed subscriber Connection on this room: it receives both
broadcasts and events addressed to its ConnId via send_event, and
unregisters itself on Drop (the RAII unsubscribe handle). Distinct from the
raw subscribe receiver, which is broadcast-only and cannot be targeted.
Sourcepub async fn conn_count(&self) -> usize
pub async fn conn_count(&self) -> usize
Snapshot the number of registered typed connections (diagnostic / test helper). Returns 0 if the actor has already exited.
Sourcepub async fn presence_members(&self) -> Vec<String>
pub async fn presence_members(&self) -> Vec<String>
Snapshot the live presence member ids (diagnostic / test helper). Returns an empty vec if the actor has already exited.
Trait Implementations§
Source§impl Clone for RoomHandle
impl Clone for RoomHandle
Source§fn clone(&self) -> RoomHandle
fn clone(&self) -> RoomHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more