pub struct WebSocketState {
pub broadcast_tx: Sender<WsServerMessage>,
pub channel_senders: RwLock<HashMap<String, Sender<WsServerMessage>>>,
pub clients: RwLock<HashMap<String, ClientInfo>>,
pub version: AtomicU64,
}Expand description
Global WebSocket state shared across connections
Fields§
§broadcast_tx: Sender<WsServerMessage>Broadcast channel for server-wide messages
channel_senders: RwLock<HashMap<String, Sender<WsServerMessage>>>Per-channel broadcast senders
clients: RwLock<HashMap<String, ClientInfo>>Connected clients info
version: AtomicU64Current sync version
Implementations§
Source§impl WebSocketState
impl WebSocketState
pub fn new() -> Self
Sourcepub fn get_channel_sender(&self, channel: &str) -> Sender<WsServerMessage>
pub fn get_channel_sender(&self, channel: &str) -> Sender<WsServerMessage>
Get or create a channel sender
Sourcepub fn broadcast_to_channel(&self, channel: &str, msg: WsServerMessage)
pub fn broadcast_to_channel(&self, channel: &str, msg: WsServerMessage)
Broadcast to a specific channel
Sourcepub fn increment_version(&self) -> u64
pub fn increment_version(&self) -> u64
Increment version and return new value
Sourcepub fn current_version(&self) -> u64
pub fn current_version(&self) -> u64
Get current version
Sourcepub fn register_client(&self, id: &str)
pub fn register_client(&self, id: &str)
Register a new client
Sourcepub fn unregister_client(&self, id: &str)
pub fn unregister_client(&self, id: &str)
Unregister a client
Sourcepub fn client_count(&self) -> usize
pub fn client_count(&self) -> usize
Get client count
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for WebSocketState
impl !RefUnwindSafe for WebSocketState
impl Send for WebSocketState
impl Sync for WebSocketState
impl Unpin for WebSocketState
impl UnsafeUnpin for WebSocketState
impl !UnwindSafe for WebSocketState
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