diff --git a/src/main.rs b/src/main.rs index 13eeadc..f5926d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -233,6 +233,7 @@ async fn inner_handle_connection( tx.unbounded_send(Message::Close(None)).ok(); } client_map.insert(msg_client_id.clone(), addr); + RoomMessageDown::create_success_reply(format!("Client replaced {:?} -> {:?}", peer_addr, addr)).send(&tx); } }, None => { @@ -249,6 +250,7 @@ async fn inner_handle_connection( } } } + RoomMessageDown::create_success_reply(format!("Client entered: {:?}", addr)).send(&tx); }, } }, @@ -257,6 +259,7 @@ async fn inner_handle_connection( let mut client_map = BTreeMap::new(); client_map.insert(msg_client_id.clone(), addr); room_map.insert(msg_room_id.clone(), client_map); + RoomMessageDown::create_success_reply(format!("Client create room: {:?}", addr)).send(&tx); }, } room_id = Some(msg_room_id); @@ -338,13 +341,16 @@ async fn inner_handle_connection( }; if let Ok(mm) = serde_json::to_string(&m) { if let Some(client_map) = client_map { + let mut sent_messages = 0; for (peer_client_id, peer_client_addr) in client_map { if peer_client_id != client_id { if let Some(peer_tx) = peer_map.lock().unwrap().get(peer_client_addr) { + sent_messages += 1; peer_tx.unbounded_send(Message::Text(mm.clone())).ok(); } } } + RoomMessageDown::create_success_reply(format!("Send message to {} peers", sent_messages)).send(&tx); } } } else { @@ -372,6 +378,7 @@ async fn inner_handle_connection( if let Some(peer_tx) = peer_map.lock().unwrap().get(peer_client_addr) { peer_tx.unbounded_send(Message::Text(mm.clone())).ok(); } + RoomMessageDown::create_success_reply(format!("Message sent to: {}", peer_id)).send(&tx); } else { RoomMessageDown::create_error_reply(format!("Peer not found: {}", peer_id)).send(&tx); }