diff --git a/server/src/incoming_message_handler.rs b/server/src/incoming_message_handler.rs index b31048b..0e2017d 100644 --- a/server/src/incoming_message_handler.rs +++ b/server/src/incoming_message_handler.rs @@ -1,10 +1,11 @@ use crate::user_handler::*; use crate::AppState; use crate::GameHandlerMessage::*; +use crate::OutgoingMessageHandlerMessage::*; use crate::UserHandlerMessage::*; use axum::extract::ws::{CloseFrame, Message}; use lib::*; -use serde_json::{from_str, to_string}; +use serde_json::from_str; use std::{net::SocketAddr, sync::Arc}; /// Handles incoming messages @@ -33,12 +34,14 @@ impl IncomingMessageHandler { } // Broadcast incoming chat message - let broadcast_message = Message::Text( - to_string::(&ChatMessage { text: msg }).unwrap(), - ); - let tx = self.state.tx_broadcast.clone(); + let msg = ChatMessage { text: msg }; + let tx = self.state.tx_outgoing_message_handler.clone(); + let btx = self.state.tx_broadcast.clone(); tokio::spawn(async move { - if let Err(e) = tx.send(broadcast_message) { + if let Err(e) = tx + .send(Broadcast((btx, ServerToClientMessage::ChatMessage(msg)))) + .await + { tracing::error!("Error broadcasting Chat message: {}", e) } });