From 8bd9fe1fb087be224bf082ab9ee989d49645570e Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 22 Jun 2023 20:05:06 +0200 Subject: [PATCH] Deafen now also mutes microphone --- crates/call/src/room.rs | 42 +++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/crates/call/src/room.rs b/crates/call/src/room.rs index 0c0855fd6cb48a3fc3f62ea3f3c2f7ab448f5702..714a1b19b57014f97c077542510297095d7d0bc0 100644 --- a/crates/call/src/room.rs +++ b/crates/call/src/room.rs @@ -1176,24 +1176,31 @@ impl Room { }) }) } + fn set_mute( + live_kit: &mut LiveKitRoom, + should_mute: bool, + cx: &mut ModelContext, + ) -> Result>> { + match &mut live_kit.microphone_track { + LocalTrack::None => Err(anyhow!("microphone was not shared")), + LocalTrack::Pending { muted, .. } => { + *muted = should_mute; + Ok(Task::Ready(Some(Ok(())))) + } + LocalTrack::Published { + track_publication, + muted, + } => { + *muted = should_mute; + Ok(cx.background().spawn(track_publication.set_mute(*muted))) + } + } + } pub fn toggle_mute(&mut self, cx: &mut ModelContext) -> Result>> { + let should_mute = self.is_muted().unwrap_or(false); if let Some(live_kit) = self.live_kit.as_mut() { - match &mut live_kit.microphone_track { - LocalTrack::None => Err(anyhow!("microphone was not shared")), - LocalTrack::Pending { muted, .. } => { - *muted = !*muted; - Ok(Task::Ready(Some(Ok(())))) - } - LocalTrack::Published { - track_publication, - muted, - } => { - *muted = !*muted; - - Ok(cx.background().spawn(track_publication.set_mute(*muted))) - } - } + Self::set_mute(live_kit, !should_mute, cx) } else { Err(anyhow!("LiveKit not started")) } @@ -1204,9 +1211,9 @@ impl Room { (*live_kit).deafened = !live_kit.deafened } - if let Some(live_kit) = &self.live_kit { + if let Some(live_kit) = self.live_kit.as_mut() { let mut tasks = Vec::with_capacity(self.remote_participants.len()); - + let _ = Self::set_mute(live_kit, live_kit.deafened, cx)?; // todo (osiewicz): we probably want to schedule it on fg/bg? for participant in self.remote_participants.values() { for track in live_kit .room @@ -1215,7 +1222,6 @@ impl Room { tasks.push(cx.foreground().spawn(track.set_enabled(!live_kit.deafened))); } } - Ok(cx.foreground().spawn(async move { for task in tasks { task.await?;