pub struct BroadcastManager { /* private fields */ }Expand description
Manages direct user messaging via WebSocket
Implementations§
Source§impl BroadcastManager
impl BroadcastManager
Sourcepub fn with_config(config: BroadcastConfig) -> Self
pub fn with_config(config: BroadcastConfig) -> Self
Create with custom config
Sourcepub async fn register_user(
&self,
tn_id: TnId,
id_tag: &str,
connection_id: &str,
) -> Receiver<BroadcastMessage>
pub async fn register_user( &self, tn_id: TnId, id_tag: &str, connection_id: &str, ) -> Receiver<BroadcastMessage>
Register a user connection for direct messaging
Returns a receiver for messages targeted at this user. The connection_id should be a unique identifier (UUID) for this specific connection, allowing multiple connections per user (multiple tabs/devices).
Sourcepub async fn unregister_user(
&self,
tn_id: TnId,
id_tag: &str,
connection_id: &str,
)
pub async fn unregister_user( &self, tn_id: TnId, id_tag: &str, connection_id: &str, )
Unregister a user connection
Removes the specific connection identified by connection_id. Other connections for the same user (other tabs) are preserved.
Sourcepub async fn send_to_user(
&self,
tn_id: TnId,
id_tag: &str,
msg: BroadcastMessage,
) -> DeliveryResult
pub async fn send_to_user( &self, tn_id: TnId, id_tag: &str, msg: BroadcastMessage, ) -> DeliveryResult
Send a message to a specific user
Delivers the message to all connections for the user (multiple tabs/devices).
Returns DeliveryResult::Delivered(n) with the number of connections that
received the message, or DeliveryResult::UserOffline if the user has no
active connections.
Sourcepub async fn send_to_tenant(&self, tn_id: TnId, msg: BroadcastMessage) -> usize
pub async fn send_to_tenant(&self, tn_id: TnId, msg: BroadcastMessage) -> usize
Send a message to all users in a tenant
Broadcasts the message to all connections for all users in the tenant. Returns the total number of connections that received the message.
Sourcepub async fn is_user_online(&self, tn_id: TnId, id_tag: &str) -> bool
pub async fn is_user_online(&self, tn_id: TnId, id_tag: &str) -> bool
Check if a user is currently online (has at least one connection)
Sourcepub async fn online_users(&self, tn_id: TnId) -> Vec<Box<str>>
pub async fn online_users(&self, tn_id: TnId) -> Vec<Box<str>>
Get list of all online users for a tenant
Sourcepub async fn user_stats(&self) -> UserRegistryStats
pub async fn user_stats(&self) -> UserRegistryStats
Get user registry statistics
Sourcepub async fn cleanup_users(&self)
pub async fn cleanup_users(&self)
Cleanup disconnected users (users with no active receivers)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BroadcastManager
impl !RefUnwindSafe for BroadcastManager
impl Send for BroadcastManager
impl Sync for BroadcastManager
impl Unpin for BroadcastManager
impl UnsafeUnpin for BroadcastManager
impl !UnwindSafe for BroadcastManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().