Skip to content

Commit 7bf3bbd

Browse files
committed
fix: call leave_room when a peer disconnects
1 parent 6653404 commit 7bf3bbd

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

server/src/main.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ async fn handle_authenticated_connection(
309309
}
310310

311311
// client disconnected gracefully
312-
handle_disconnect(state, peer).await;
312+
handle_disconnect(state, &mut peer).await;
313313

314314
Ok(())
315315
}
@@ -463,19 +463,14 @@ async fn handle_message(
463463
}
464464
}
465465

466-
async fn handle_disconnect(state: Arc<Mutex<Shared>>, peer: Peer) {
466+
async fn handle_disconnect(state: Arc<Mutex<Shared>>, peer: &mut Peer) {
467+
// remove them from the room cleanly and notify others
468+
leave_room(state.clone(), peer).await;
469+
470+
// remove name from the map
467471
let mut state = state.lock().await;
468472
state.names.remove(&peer.id);
469-
let names = state.names.clone();
470-
471-
if let Some(room_id) = peer.room_id {
472-
let room = state.rooms.get_mut(&room_id).unwrap();
473-
474-
room.peers.remove(&peer.id);
475-
476-
let msg = room.connected_users_info(names);
477-
room.broadcast(&msg).await;
478-
}
479473

480-
// TODO: notify waiting peers of new room list
474+
// remove handle
475+
state.waiting_peers.remove(&peer.id);
481476
}

0 commit comments

Comments
 (0)