pub struct WebSocketState { /* private fields */ }Expand description
WebSocket connection state manager.
Each connection has an outgoing queue of message_buffer_size messages; messages for a
client whose queue is full are dropped rather than buffered without bound.
Implementations§
Source§impl WebSocketState
impl WebSocketState
pub fn new(config: WebSocketConfig) -> Self
Sourcepub fn config(&self) -> &WebSocketConfig
pub fn config(&self) -> &WebSocketConfig
The configuration the state was created with.
Sourcepub async fn serve_connection(
state: Arc<RwLock<WebSocketState>>,
websocket: WebSocket,
) -> Result<()>
pub async fn serve_connection( state: Arc<RwLock<WebSocketState>>, websocket: WebSocket, ) -> Result<()>
Serve one WebSocket connection until it closes.
The shared state is only locked for the short moments that register the connection,
handle a client message and unregister it, never while waiting for the client: a
connection that held the lock for its whole lifetime would block every other connection,
the ping task and the broadcast listener.
Sourcepub async fn broadcast_to_all(&self, message: ServerMessage) -> Result<()>
pub async fn broadcast_to_all(&self, message: ServerMessage) -> Result<()>
Broadcast a message to all connected clients
Sourcepub async fn broadcast_to_subscribed(
&self,
message: ServerMessage,
event_type: &str,
) -> Result<()>
pub async fn broadcast_to_subscribed( &self, message: ServerMessage, event_type: &str, ) -> Result<()>
Broadcast a message to the clients subscribed to event_type
Sourcepub async fn publish_archive_event(&self, event: ArchiveEvent) -> Result<()>
pub async fn publish_archive_event(&self, event: ArchiveEvent) -> Result<()>
Publish an archive event to all connected clients
Sourcepub async fn ping_all_connections(&self)
pub async fn ping_all_connections(&self)
Send ping to all connections to keep them alive
Sourcepub fn connection_count(&self) -> usize
pub fn connection_count(&self) -> usize
Get current connection count
Sourcepub async fn start_broadcast_listener(
state: Arc<RwLock<WebSocketState>>,
) -> Result<()>
pub async fn start_broadcast_listener( state: Arc<RwLock<WebSocketState>>, ) -> Result<()>
Start the broadcast listener task
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 more