diff --git a/server/src/websocket.rs b/server/src/websocket.rs index b549df7..39f7898 100644 --- a/server/src/websocket.rs +++ b/server/src/websocket.rs @@ -39,6 +39,7 @@ pub async fn websocket_on_connection(stream: WebSocket, state: Arc, ad // Split channels to send and receive asynchronously. let (mut sender, mut receiver) = stream.split(); + // Create channel for direct messages let (dm_tx, mut dm_rx) = mpsc::channel(30); let _ = state @@ -55,13 +56,15 @@ pub async fn websocket_on_connection(stream: WebSocket, state: Arc, ad // Send messages to this client let mut send_task = tokio::spawn(async move { loop { + // Global broadcast channel while let Ok(msg) = rx.recv().await { if sender.send(Message::Text(msg)).await.is_err() { break; } } - while let Some(message) = dm_rx.recv().await { - if sender.send(message).await.is_err() { + // Direct message channel + while let Some(msg) = dm_rx.recv().await { + if sender.send(msg).await.is_err() { break; } }