From a71180257d1c63c1dca670290d50776b91d75730 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 27 Nov 2023 15:12:13 +0100 Subject: [PATCH] Add deafening support --- crates/call2/src/call2.rs | 23 +++++++++++++++++++ crates/collab_ui2/src/collab_titlebar_item.rs | 22 +++++++++++++++++- crates/collab_ui2/src/face_pile.rs | 2 +- crates/workspace2/src/workspace2.rs | 8 +++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/crates/call2/src/call2.rs b/crates/call2/src/call2.rs index 1cffc44f93..d983af50b7 100644 --- a/crates/call2/src/call2.rs +++ b/crates/call2/src/call2.rs @@ -686,6 +686,29 @@ impl CallHandler for Call { }) }); } + fn toggle_deafen(&self, cx: &mut AppContext) { + self.active_call.as_ref().map(|call| { + call.0.update(cx, |this, cx| { + this.room().map(|room| { + room.update(cx, |this, cx| { + this.toggle_deafen(cx).log_err(); + }) + }) + }) + }); + } + fn is_deafened(&self, cx: &AppContext) -> Option { + self.active_call + .as_ref() + .map(|call| { + call.0 + .read(cx) + .room() + .map(|room| room.read(cx).is_deafened()) + }) + .flatten() + .flatten() + } } #[cfg(test)] diff --git a/crates/collab_ui2/src/collab_titlebar_item.rs b/crates/collab_ui2/src/collab_titlebar_item.rs index 0ba5c3e707..a58186d0f0 100644 --- a/crates/collab_ui2/src/collab_titlebar_item.rs +++ b/crates/collab_ui2/src/collab_titlebar_item.rs @@ -111,6 +111,17 @@ impl Render for CollabTitlebarItem { } else { ui::Icon::Mic }; + let speakers_icon = if self + .workspace + .update(cx, |this, cx| this.call_state().is_deafened(cx)) + .log_err() + .flatten() + .unwrap_or_default() + { + ui::Icon::AudioOff + } else { + ui::Icon::AudioOn + }; let workspace = self.workspace.clone(); h_stack() .id("titlebar") @@ -233,7 +244,16 @@ impl Render for CollabTitlebarItem { .log_err(); } })) - .child(IconButton::new("mute-sound", ui::Icon::AudioOn)) + .child(IconButton::new("mute-sound", speakers_icon).on_click({ + let workspace = workspace.clone(); + move |_, cx| { + workspace + .update(cx, |this, cx| { + this.call_state().toggle_deafen(cx); + }) + .log_err(); + } + })) .child(IconButton::new("screen-share", ui::Icon::Screen).on_click( move |_, cx| { workspace diff --git a/crates/collab_ui2/src/face_pile.rs b/crates/collab_ui2/src/face_pile.rs index 953470b854..61a2ef85b5 100644 --- a/crates/collab_ui2/src/face_pile.rs +++ b/crates/collab_ui2/src/face_pile.rs @@ -17,7 +17,7 @@ impl RenderOnce for FacePile { let player_list = self.faces.into_iter().enumerate().map(|(ix, player)| { let isnt_last = ix < player_count - 1; - div().when(isnt_last, |div| div.neg_mr_2()).child(player) + div().when(isnt_last, |div| div.neg_mr_1()).child(player) }); div().p_1().flex().items_center().children(player_list) } diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index 73bfc63332..f906a19498 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -371,6 +371,12 @@ impl CallHandler for TestCallHandler { fn toggle_mute(&self, cx: &mut AppContext) {} fn toggle_screen_share(&self, cx: &mut AppContext) {} + + fn toggle_deafen(&self, cx: &mut AppContext) {} + + fn is_deafened(&self, cx: &AppContext) -> Option { + None + } } impl AppState { @@ -483,7 +489,9 @@ pub trait CallHandler { ) -> Task>; fn remote_participants(&self, cx: &AppContext) -> Option, PeerId)>>; fn is_muted(&self, cx: &AppContext) -> Option; + fn is_deafened(&self, cx: &AppContext) -> Option; fn toggle_mute(&self, cx: &mut AppContext); + fn toggle_deafen(&self, cx: &mut AppContext); fn toggle_screen_share(&self, cx: &mut AppContext); }