Skip to main content

RoomRegistry

Trait RoomRegistry 

Source
pub trait RoomRegistry: Send + Sync {
    // Required methods
    fn get_or_create(&self, room_id: &str) -> Arc<Room> ⓘ;
    fn get(&self, room_id: &str) -> Option<Arc<Room>>;
    fn remove(&self, room_id: &str) -> Option<Arc<Room>>;
    fn room_count(&self) -> usize;
    fn room_ids(&self) -> Vec<String>;
    fn total_participants(&self) -> usize;
    fn cleanup(&self) -> usize;
    fn cleanup_empty(&self) -> usize;
}
Expand description

Storage for rooms, abstracted so a room collection can be swapped without changing room/messaging code (0.4.0).

The canonical single-node implementation is RoomManager (in-memory DashMap). The multi-node implementation is crate::redis_rooms::RedisRoomRegistry (feature redis), which delegates to an inner RoomManager for the local node and fans broadcasts out through Redis pub/sub.

Required Methods§

Source

fn get_or_create(&self, room_id: &str) -> Arc<Room> ⓘ

Get an existing room or create it.

Source

fn get(&self, room_id: &str) -> Option<Arc<Room>>

Get a room if it exists.

Source

fn remove(&self, room_id: &str) -> Option<Arc<Room>>

Remove a room by id, returning it if present.

Source

fn room_count(&self) -> usize

Number of rooms.

Source

fn room_ids(&self) -> Vec<String>

List room ids.

Source

fn total_participants(&self) -> usize

Total participants across all rooms.

Source

fn cleanup(&self) -> usize

Remove all empty rooms (no participants, no receivers). Returns number removed.

Source

fn cleanup_empty(&self) -> usize

Remove all rooms with zero participants (regardless of receivers). Returns number removed.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl RoomRegistry for RoomManager

Source§

impl<C> RoomRegistry for RedisRoomRegistry<C>
where C: ConnectionLike + Clone + Send + 'static,

Available on crate feature redis only.