fix chat
This commit is contained in:
parent
a2af394bb9
commit
30e6091749
1 changed files with 9 additions and 6 deletions
|
@ -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>(&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)
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue