pub struct Room {
pub id: String,
/* private fields */
}Expand description
A single broadcast room with a participant roster.
Fields§
§id: StringRoom identifier.
Implementations§
Source§impl Room
impl Room
Sourcepub fn new(id: impl Into<String>, capacity: usize) -> Self
pub fn new(id: impl Into<String>, capacity: usize) -> Self
Create a new room with the given id and broadcast capacity.
Sourcepub fn with_stats(
id: impl Into<String>,
capacity: usize,
stats: Option<StatsRecorder>,
) -> Self
pub fn with_stats( id: impl Into<String>, capacity: usize, stats: Option<StatsRecorder>, ) -> Self
Create a new room that records outbound traffic and drops into
stats (0.4.0 backpressure hook — see crate::stats).
Sourcepub fn subscribe(&self) -> Receiver<Frame>
pub fn subscribe(&self) -> Receiver<Frame>
Subscribe to this room’s messages (text and binary).
Sourcepub fn broadcast(&self, msg: impl Into<Frame>) -> Result<usize, WsError>
pub fn broadcast(&self, msg: impl Into<Frame>) -> Result<usize, WsError>
Broadcast a frame (text or binary) to all participants.
Accepts anything Frame converts from — String, &str,
bytes::Bytes, Vec<u8> — with no re-encoding for owned payloads.
§Errors
Returns WsError::BroadcastFull when the room has no active
receivers; with a StatsRecorder attached this also counts as a
drop (backpressure loss).
Sourcepub fn join(&self, participant_id: u32, name: String)
pub fn join(&self, participant_id: u32, name: String)
Add a participant (or refresh its display name on re-join).
Sourcepub fn leave(&self, participant_id: u32) -> bool
pub fn leave(&self, participant_id: u32) -> bool
Remove a participant. Returns true if it was present.
Sourcepub fn participants(&self) -> Vec<(u32, String)>
pub fn participants(&self) -> Vec<(u32, String)>
Snapshot of (participant_id, name) pairs.
Sourcepub fn participant_names(&self) -> Vec<String>
pub fn participant_names(&self) -> Vec<String>
Snapshot of participant display names.
Sourcepub fn participant_count(&self) -> usize
pub fn participant_count(&self) -> usize
Number of tracked participants.
Sourcepub fn receiver_count(&self) -> usize
pub fn receiver_count(&self) -> usize
Number of active broadcast receivers.