pub struct WebSocketServer { /* private fields */ }
Expand description
WebSocket server - integrates with elif HTTP server
Implementations§
Source§impl WebSocketServer
impl WebSocketServer
Sourcepub fn with_config(config: WebSocketConfig) -> Self
pub fn with_config(config: WebSocketConfig) -> Self
Create with custom configuration
Sourcepub fn registry(&self) -> Arc<ConnectionRegistry>
pub fn registry(&self) -> Arc<ConnectionRegistry>
Get the connection registry
Sourcepub async fn stats(&self) -> RegistryStats
pub async fn stats(&self) -> RegistryStats
Get server statistics
Sourcepub fn add_websocket_route<F, Fut>(
&self,
router: ElifRouter,
path: &str,
_handler: F,
) -> ElifRouterwhere
F: Fn(ConnectionId, Arc<WebSocketConnection>) -> Fut + Send + Sync + Clone + 'static,
Fut: Future<Output = ()> + Send + 'static,
pub fn add_websocket_route<F, Fut>(
&self,
router: ElifRouter,
path: &str,
_handler: F,
) -> ElifRouterwhere
F: Fn(ConnectionId, Arc<WebSocketConnection>) -> Fut + Send + Sync + Clone + 'static,
Fut: Future<Output = ()> + Send + 'static,
Add a WebSocket route to the router using a simple closure For now, this is a placeholder that will be improved in later iterations
Sourcepub fn add_handler<F, Fut>(
&self,
router: ElifRouter,
path: &str,
handler: F,
) -> ElifRouterwhere
F: Fn(ConnectionId, Arc<WebSocketConnection>) -> Fut + Send + Sync + Clone + 'static,
Fut: Future<Output = ()> + Send + 'static,
pub fn add_handler<F, Fut>(
&self,
router: ElifRouter,
path: &str,
handler: F,
) -> ElifRouterwhere
F: Fn(ConnectionId, Arc<WebSocketConnection>) -> Fut + Send + Sync + Clone + 'static,
Fut: Future<Output = ()> + Send + 'static,
Add a simple WebSocket handler function (alias for add_websocket_route)
Sourcepub async fn broadcast(&self, message: WebSocketMessage) -> BroadcastResult
pub async fn broadcast(&self, message: WebSocketMessage) -> BroadcastResult
Broadcast a message to all connections
Sourcepub async fn broadcast_text<T: Into<String>>(&self, text: T) -> BroadcastResult
pub async fn broadcast_text<T: Into<String>>(&self, text: T) -> BroadcastResult
Broadcast text to all connections
Sourcepub async fn broadcast_binary<T: Into<Vec<u8>>>(
&self,
data: T,
) -> BroadcastResult
pub async fn broadcast_binary<T: Into<Vec<u8>>>( &self, data: T, ) -> BroadcastResult
Broadcast binary data to all connections
Sourcepub async fn send_to_connection(
&self,
id: ConnectionId,
message: WebSocketMessage,
) -> WebSocketResult<()>
pub async fn send_to_connection( &self, id: ConnectionId, message: WebSocketMessage, ) -> WebSocketResult<()>
Send a message to a specific connection
Sourcepub async fn send_text_to_connection<T: Into<String>>(
&self,
id: ConnectionId,
text: T,
) -> WebSocketResult<()>
pub async fn send_text_to_connection<T: Into<String>>( &self, id: ConnectionId, text: T, ) -> WebSocketResult<()>
Send text to a specific connection
Sourcepub async fn send_binary_to_connection<T: Into<Vec<u8>>>(
&self,
id: ConnectionId,
data: T,
) -> WebSocketResult<()>
pub async fn send_binary_to_connection<T: Into<Vec<u8>>>( &self, id: ConnectionId, data: T, ) -> WebSocketResult<()>
Send binary data to a specific connection
Sourcepub async fn get_connection_ids(&self) -> Vec<ConnectionId>
pub async fn get_connection_ids(&self) -> Vec<ConnectionId>
Get all active connection IDs
Sourcepub async fn connection_count(&self) -> usize
pub async fn connection_count(&self) -> usize
Get the number of active connections
Sourcepub async fn close_connection(&self, id: ConnectionId) -> WebSocketResult<()>
pub async fn close_connection(&self, id: ConnectionId) -> WebSocketResult<()>
Close a specific connection
Sourcepub async fn close_all_connections(&self) -> CloseAllResult
pub async fn close_all_connections(&self) -> CloseAllResult
Close all connections
Sourcepub fn start_cleanup_task(&mut self, interval_seconds: u64)
pub fn start_cleanup_task(&mut self, interval_seconds: u64)
Start the cleanup task for inactive connections
Sourcepub fn stop_cleanup_task(&mut self)
pub fn stop_cleanup_task(&mut self)
Stop the cleanup task
Trait Implementations§
Source§impl Default for WebSocketServer
impl Default for WebSocketServer
Auto Trait Implementations§
impl Freeze for WebSocketServer
impl !RefUnwindSafe for WebSocketServer
impl Send for WebSocketServer
impl Sync for WebSocketServer
impl Unpin for WebSocketServer
impl !UnwindSafe for WebSocketServer
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