Add deafening support

Piotr Osiewicz created

Change summary

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(-)

Detailed changes

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<bool> {
+        self.active_call
+            .as_ref()
+            .map(|call| {
+                call.0
+                    .read(cx)
+                    .room()
+                    .map(|room| room.read(cx).is_deafened())
+            })
+            .flatten()
+            .flatten()
+    }
 }
 
 #[cfg(test)]

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

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)
     }

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<bool> {
+        None
+    }
 }
 
 impl AppState {
@@ -483,7 +489,9 @@ pub trait CallHandler {
     ) -> Task<Result<()>>;
     fn remote_participants(&self, cx: &AppContext) -> Option<Vec<(Arc<User>, PeerId)>>;
     fn is_muted(&self, cx: &AppContext) -> Option<bool>;
+    fn is_deafened(&self, cx: &AppContext) -> Option<bool>;
     fn toggle_mute(&self, cx: &mut AppContext);
+    fn toggle_deafen(&self, cx: &mut AppContext);
     fn toggle_screen_share(&self, cx: &mut AppContext);
 }