From d2a87976645e963ece122518a90b9ca0fd10f0e5 Mon Sep 17 00:00:00 2001 From: Christopher Roddy <76755988+cjrkoa@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:35:32 -0400 Subject: [PATCH] unicast room messages fixes #1100 in progress --- crates/ott-balancer-bin/src/balancer.rs | 28 +++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/crates/ott-balancer-bin/src/balancer.rs b/crates/ott-balancer-bin/src/balancer.rs index 6bfc0d388..c4730fe21 100644 --- a/crates/ott-balancer-bin/src/balancer.rs +++ b/crates/ott-balancer-bin/src/balancer.rs @@ -555,7 +555,7 @@ pub async fn dispatch_monolith_message( let msg: MsgM2B = msg.message().deserialize()?; debug!("got message from monolith: {:?}", msg); - + match msg { MsgM2B::Init(_) => { warn!( @@ -622,17 +622,23 @@ pub async fn dispatch_monolith_message( }; // TODO: also handle the case where the client_id is Some - - // broadcast to all clients - debug!("broadcasting to clients in room: {:?}", room.name()); - // TODO: optimize this using a broadcast channel let built_msg = Message::text(msg.payload.to_string()); - for client in room.clients() { - let Some(client) = ctx_read.clients.get(client) else { - anyhow::bail!("client not found"); - }; - - client.send(built_msg.clone()).await?; + + match ctx_read.clients.get(&msg.client_id) { + Some(client) => { + client.send(built_msg.clone()).await?; + } + None => { + // broadcast to all clients + debug!("broadcasting to clients in room: {:?}", room.name()); + // TODO: optimize this using a broadcast channel + for client in room.clients() { + let Some(client) = ctx_read.clients.get(client) else { + anyhow::bail!("client not found"); + }; + client.send(built_msg.clone()).await?; + } + } } } MsgM2B::Kick(msg) => {