pub struct WebSocketManager { /* private fields */ }Expand description
WebSocket connection manager
Implementations§
Source§impl WebSocketManager
impl WebSocketManager
Sourcepub async fn connection_count(&self) -> usize
pub async fn connection_count(&self) -> usize
Get the number of active connections
Sourcepub async fn register(
&self,
id: String,
user_id: Option<String>,
sender: Option<Sender<String>>,
)
pub async fn register( &self, id: String, user_id: Option<String>, sender: Option<Sender<String>>, )
Register a new connection
Sourcepub async fn unregister(&self, id: &str)
pub async fn unregister(&self, id: &str)
Remove a connection and clean up its room memberships
Sourcepub async fn get_connection_ids(&self) -> Vec<String>
pub async fn get_connection_ids(&self) -> Vec<String>
Get all connection IDs
Sourcepub async fn send(&self, id: &str, msg: String) -> Result<(), &'static str>
pub async fn send(&self, id: &str, msg: String) -> Result<(), &'static str>
Send a message to a specific connection by ID
Sourcepub async fn send_to_user(&self, user_id: &str, msg: String)
pub async fn send_to_user(&self, user_id: &str, msg: String)
Send a message to all connections belonging to a specific user
Sourcepub async fn send_json<T: Serialize>(
&self,
id: &str,
data: &T,
) -> Result<(), String>
pub async fn send_json<T: Serialize>( &self, id: &str, data: &T, ) -> Result<(), String>
Send a JSON-serializable value to a specific connection
Sourcepub async fn broadcast_json<T: Serialize>(&self, data: &T) -> Result<(), String>
pub async fn broadcast_json<T: Serialize>(&self, data: &T) -> Result<(), String>
Broadcast a JSON-serializable value to all connections
Sourcepub async fn leave_room(&self, conn_id: &str, room: &str)
pub async fn leave_room(&self, conn_id: &str, room: &str)
Remove a connection from a room
Sourcepub async fn send_to_room(&self, room: &str, msg: String)
pub async fn send_to_room(&self, room: &str, msg: String)
Send a message to all connections in a room
Sourcepub async fn get_room_members(&self, room: &str) -> Vec<String>
pub async fn get_room_members(&self, room: &str) -> Vec<String>
Get all connection IDs in a room
Sourcepub fn start_keepalive(self: Arc<Self>, interval_secs: u64) -> JoinHandle<()> ⓘ
pub fn start_keepalive(self: Arc<Self>, interval_secs: u64) -> JoinHandle<()> ⓘ
Start a background keepalive loop that pings connections and removes dead ones
Sourcepub async fn check_rate_limit(&self, id: &str, max_per_sec: u32) -> bool
pub async fn check_rate_limit(&self, id: &str, max_per_sec: u32) -> bool
Check if a connection is within its rate limit.
Returns true if allowed, false if rate-limited.
Records the timestamp if allowed.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for WebSocketManager
impl !UnwindSafe for WebSocketManager
impl Freeze for WebSocketManager
impl Send for WebSocketManager
impl Sync for WebSocketManager
impl Unpin for WebSocketManager
impl UnsafeUnpin for WebSocketManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more