Skip to content

Commit 102b0c5

Browse files
committed
fix: send new roomlist to everyone when it changes
1 parent 460dded commit 102b0c5

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

‎server/src/main.rs‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ impl Shared {
126126
}
127127
}
128128

129+
async fn notify(&mut self, notification: Notification) {
130+
let m = Message::Notification(notification);
131+
for p in self.waiting_peers.values_mut() {
132+
let _ = p.tx.send(m.clone());
133+
}
134+
135+
for r in self.rooms.values_mut() {
136+
r.broadcast(&m).await;
137+
}
138+
}
139+
129140
fn room_list_notification(&self) -> Notification {
130141
let list: Vec<RoomListing> = self
131142
.rooms
@@ -301,6 +312,9 @@ async fn leave_room(
301312

302313
state.waiting_peers.insert(peer.id.clone(), handle);
303314

315+
let room_list = state.room_list_notification();
316+
state.notify(room_list).await;
317+
304318
Ok(true)
305319
}
306320

@@ -333,10 +347,8 @@ async fn join_room(
333347
peer.notify(room.playing_notification()).await?;
334348
peer.notify(room.queue_notification()).await?;
335349

336-
drop(state);
337-
338-
let state = state_mutex.lock().await;
339-
peer.notify(state.room_list_notification()).await?;
350+
let room_list = state.room_list_notification();
351+
state.notify(room_list).await;
340352

341353
Ok(true)
342354
}
@@ -500,6 +512,9 @@ async fn handle_request(
500512
let room = Room::new(options.clone());
501513
state.rooms.insert(room_id, room);
502514

515+
let room_list = state.room_list_notification();
516+
state.notify(room_list).await;
517+
503518
Ok(Some(Response::CreateRoomResponse(room_id)))
504519
}
505520

0 commit comments

Comments
 (0)