Add call events

Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
Joseph T. Lyons 2023-07-11 13:58:55 -04:00
parent 8161438a85
commit 98a0113ac3
7 changed files with 57 additions and 21 deletions

View File

@ -4,7 +4,7 @@ pub mod room;
use std::sync::Arc; use std::sync::Arc;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use client::{proto, Client, TypedEnvelope, User, UserStore}; use client::{proto, ClickhouseEvent, Client, TelemetrySettings, TypedEnvelope, User, UserStore};
use collections::HashSet; use collections::HashSet;
use futures::{future::Shared, FutureExt}; use futures::{future::Shared, FutureExt};
use postage::watch; use postage::watch;
@ -198,6 +198,7 @@ impl ActiveCall {
let result = invite.await; let result = invite.await;
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
this.pending_invites.remove(&called_user_id); this.pending_invites.remove(&called_user_id);
this.report_call_event("invite", cx);
cx.notify(); cx.notify();
}); });
result result
@ -243,21 +244,26 @@ impl ActiveCall {
}; };
let join = Room::join(&call, self.client.clone(), self.user_store.clone(), cx); let join = Room::join(&call, self.client.clone(), self.user_store.clone(), cx);
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
let room = join.await?; let room = join.await?;
this.update(&mut cx, |this, cx| this.set_room(Some(room.clone()), cx)) this.update(&mut cx, |this, cx| this.set_room(Some(room.clone()), cx))
.await?; .await?;
this.update(&mut cx, |this, cx| {
this.report_call_event("accept incoming", cx)
});
Ok(()) Ok(())
}) })
} }
pub fn decline_incoming(&mut self) -> Result<()> { pub fn decline_incoming(&mut self, cx: &mut ModelContext<Self>) -> Result<()> {
let call = self let call = self
.incoming_call .incoming_call
.0 .0
.borrow_mut() .borrow_mut()
.take() .take()
.ok_or_else(|| anyhow!("no incoming call"))?; .ok_or_else(|| anyhow!("no incoming call"))?;
self.report_call_event_for_room("decline incoming", call.room_id, cx);
self.client.send(proto::DeclineCall { self.client.send(proto::DeclineCall {
room_id: call.room_id, room_id: call.room_id,
})?; })?;
@ -266,6 +272,7 @@ impl ActiveCall {
pub fn hang_up(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> { pub fn hang_up(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
cx.notify(); cx.notify();
self.report_call_event("hang up", cx);
if let Some((room, _)) = self.room.take() { if let Some((room, _)) = self.room.take() {
room.update(cx, |room, cx| room.leave(cx)) room.update(cx, |room, cx| room.leave(cx))
} else { } else {
@ -273,12 +280,28 @@ impl ActiveCall {
} }
} }
pub fn toggle_screen_sharing(&self, cx: &mut AppContext) {
if let Some(room) = self.room().cloned() {
let toggle_screen_sharing = room.update(cx, |room, cx| {
if room.is_screen_sharing() {
self.report_call_event("disable screen share", cx);
Task::ready(room.unshare_screen(cx))
} else {
self.report_call_event("enable screen share", cx);
room.share_screen(cx)
}
});
toggle_screen_sharing.detach_and_log_err(cx);
}
}
pub fn share_project( pub fn share_project(
&mut self, &mut self,
project: ModelHandle<Project>, project: ModelHandle<Project>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Task<Result<u64>> { ) -> Task<Result<u64>> {
if let Some((room, _)) = self.room.as_ref() { if let Some((room, _)) = self.room.as_ref() {
self.report_call_event("share project", cx);
room.update(cx, |room, cx| room.share_project(project, cx)) room.update(cx, |room, cx| room.share_project(project, cx))
} else { } else {
Task::ready(Err(anyhow!("no active call"))) Task::ready(Err(anyhow!("no active call")))
@ -291,6 +314,7 @@ impl ActiveCall {
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Result<()> { ) -> Result<()> {
if let Some((room, _)) = self.room.as_ref() { if let Some((room, _)) = self.room.as_ref() {
self.report_call_event("unshare project", cx);
room.update(cx, |room, cx| room.unshare_project(project, cx)) room.update(cx, |room, cx| room.unshare_project(project, cx))
} else { } else {
Err(anyhow!("no active call")) Err(anyhow!("no active call"))
@ -352,4 +376,19 @@ impl ActiveCall {
pub fn pending_invites(&self) -> &HashSet<u64> { pub fn pending_invites(&self) -> &HashSet<u64> {
&self.pending_invites &self.pending_invites
} }
fn report_call_event(&self, operation: &'static str, cx: &AppContext) {
if let Some(room) = self.room() {
self.report_call_event_for_room(operation, room.read(cx).id(), cx)
}
}
fn report_call_event_for_room(&self, operation: &'static str, room_id: u64, cx: &AppContext) {
let telemetry = self.client.telemetry();
let telemetry_settings = *settings::get::<TelemetrySettings>(cx);
let event = ClickhouseEvent::Call { operation, room_id };
telemetry.report_clickhouse_event(event, telemetry_settings);
}
} }

View File

@ -70,6 +70,10 @@ pub enum ClickhouseEvent {
suggestion_accepted: bool, suggestion_accepted: bool,
file_extension: Option<String>, file_extension: Option<String>,
}, },
Call {
operation: &'static str,
room_id: u64,
},
} }
#[cfg(debug_assertions)] #[cfg(debug_assertions)]

View File

@ -157,7 +157,7 @@ async fn test_basic_calls(
// User C receives the call, but declines it. // User C receives the call, but declines it.
let call_c = incoming_call_c.next().await.unwrap().unwrap(); let call_c = incoming_call_c.next().await.unwrap().unwrap();
assert_eq!(call_c.calling_user.github_login, "user_b"); assert_eq!(call_c.calling_user.github_login, "user_b");
active_call_c.update(cx_c, |call, _| call.decline_incoming().unwrap()); active_call_c.update(cx_c, |call, cx| call.decline_incoming(cx).unwrap());
assert!(incoming_call_c.next().await.unwrap().is_none()); assert!(incoming_call_c.next().await.unwrap().is_none());
deterministic.run_until_parked(); deterministic.run_until_parked();
@ -1080,7 +1080,7 @@ async fn test_calls_on_multiple_connections(
// User B declines the call on one of the two connections, causing both connections // User B declines the call on one of the two connections, causing both connections
// to stop ringing. // to stop ringing.
active_call_b2.update(cx_b2, |call, _| call.decline_incoming().unwrap()); active_call_b2.update(cx_b2, |call, cx| call.decline_incoming(cx).unwrap());
deterministic.run_until_parked(); deterministic.run_until_parked();
assert!(incoming_call_b1.next().await.unwrap().is_none()); assert!(incoming_call_b1.next().await.unwrap().is_none());
assert!(incoming_call_b2.next().await.unwrap().is_none()); assert!(incoming_call_b2.next().await.unwrap().is_none());
@ -5945,7 +5945,7 @@ async fn test_contacts(
[("user_b".to_string(), "online", "busy")] [("user_b".to_string(), "online", "busy")]
); );
active_call_b.update(cx_b, |call, _| call.decline_incoming().unwrap()); active_call_b.update(cx_b, |call, cx| call.decline_incoming(cx).unwrap());
deterministic.run_until_parked(); deterministic.run_until_parked();
assert_eq!( assert_eq!(
contacts(&client_a, cx_a), contacts(&client_a, cx_a),

View File

@ -365,7 +365,7 @@ async fn apply_client_operation(
} }
log::info!("{}: declining incoming call", client.username); log::info!("{}: declining incoming call", client.username);
active_call.update(cx, |call, _| call.decline_incoming())?; active_call.update(cx, |call, cx| call.decline_incoming(cx))?;
} }
ClientOperation::LeaveCall => { ClientOperation::LeaveCall => {

View File

@ -11,7 +11,7 @@ mod sharing_status_indicator;
use call::{ActiveCall, Room}; use call::{ActiveCall, Room};
pub use collab_titlebar_item::{CollabTitlebarItem, ToggleContactsMenu}; pub use collab_titlebar_item::{CollabTitlebarItem, ToggleContactsMenu};
use gpui::{actions, AppContext, Task}; use gpui::{actions, AppContext};
use std::sync::Arc; use std::sync::Arc;
use util::ResultExt; use util::ResultExt;
use workspace::AppState; use workspace::AppState;
@ -44,16 +44,9 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
} }
pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) { pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() { ActiveCall::global(cx).update(cx, |call, cx| {
let toggle_screen_sharing = room.update(cx, |room, cx| { call.toggle_screen_sharing(cx);
if room.is_screen_sharing() {
Task::ready(room.unshare_screen(cx))
} else {
room.share_screen(cx)
}
}); });
toggle_screen_sharing.detach_and_log_err(cx);
}
} }
pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) { pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {

View File

@ -99,8 +99,8 @@ impl IncomingCallNotification {
}) })
.detach_and_log_err(cx); .detach_and_log_err(cx);
} else { } else {
active_call.update(cx, |active_call, _| { active_call.update(cx, |active_call, cx| {
active_call.decline_incoming().log_err(); active_call.decline_incoming(cx).log_err();
}); });
} }
} }

View File

@ -7565,7 +7565,7 @@ impl Editor {
fn report_editor_event( fn report_editor_event(
&self, &self,
name: &'static str, operation: &'static str,
file_extension: Option<String>, file_extension: Option<String>,
cx: &AppContext, cx: &AppContext,
) { ) {
@ -7602,7 +7602,7 @@ impl Editor {
let event = ClickhouseEvent::Editor { let event = ClickhouseEvent::Editor {
file_extension, file_extension,
vim_mode, vim_mode,
operation: name, operation,
copilot_enabled, copilot_enabled,
copilot_enabled_for_language, copilot_enabled_for_language,
}; };