Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

collab: Add action to copy room id (#44004)

Agus Zubiaga3d5873854813
diff --git a/crates/call/src/call_impl/room.rs b/crates/call/src/call_impl/room.rs
index 2a540619d45..fc15b4e4395 100644
--- a/crates/call/src/call_impl/room.rs
+++ b/crates/call/src/call_impl/room.rs
@@ -524,6 +524,16 @@ impl Room {
self.id
}
+ pub fn room_id(&self) -> impl Future<Output = Option<String>> + 'static {
+ let room = self.live_kit.as_ref().map(|lk| lk.room.clone());
+ async move {
+ let room = room?;
+ let sid = room.sid().await;
+ let name = room.name();
+ Some(format!("{} (sid: {sid})", name))
+ }
+ }
+
pub fn status(&self) -> RoomStatus {
self.status
}
diff --git a/crates/collab_ui/src/collab_panel.rs b/crates/collab_ui/src/collab_panel.rs
index 618348307f1..7137af21d31 100644
--- a/crates/collab_ui/src/collab_panel.rs
+++ b/crates/collab_ui/src/collab_panel.rs
@@ -37,7 +37,7 @@ use ui::{
};
use util::{ResultExt, TryFutureExt, maybe};
use workspace::{
- Deafen, LeaveCall, Mute, OpenChannelNotes, ScreenShare, ShareProject, Workspace,
+ CopyRoomId, Deafen, LeaveCall, Mute, OpenChannelNotes, ScreenShare, ShareProject, Workspace,
dock::{DockPosition, Panel, PanelEvent},
notifications::{DetachAndPromptErr, NotifyResultExt},
};
@@ -128,6 +128,32 @@ pub fn init(cx: &mut App) {
workspace.register_action(|_, _: &LeaveCall, window, cx| {
CollabPanel::leave_call(window, cx);
});
+ workspace.register_action(|workspace, _: &CopyRoomId, window, cx| {
+ use workspace::notifications::{NotificationId, NotifyTaskExt as _};
+
+ struct RoomIdCopiedToast;
+
+ if let Some(room) = ActiveCall::global(cx).read(cx).room() {
+ let romo_id_fut = room.read(cx).room_id();
+ cx.spawn(async move |workspace, cx| {
+ let room_id = romo_id_fut.await.context("Failed to get livekit room")?;
+ workspace.update(cx, |workspace, cx| {
+ cx.write_to_clipboard(ClipboardItem::new_string(room_id));
+ workspace.show_toast(
+ workspace::Toast::new(
+ NotificationId::unique::<RoomIdCopiedToast>(),
+ "Room ID copied to clipboard",
+ )
+ .autohide(),
+ cx,
+ );
+ })
+ })
+ .detach_and_notify_err(window, cx);
+ } else {
+ workspace.show_error(&"There’s no active call; join one first.", cx);
+ }
+ });
workspace.register_action(|workspace, _: &ShareProject, window, cx| {
let project = workspace.project().clone();
println!("{project:?}");
diff --git a/crates/livekit_client/src/livekit_client.rs b/crates/livekit_client/src/livekit_client.rs
index 30a13bd910d..5d31f802c81 100644
--- a/crates/livekit_client/src/livekit_client.rs
+++ b/crates/livekit_client/src/livekit_client.rs
@@ -98,6 +98,14 @@ impl Room {
self.room.connection_state()
}
+ pub fn name(&self) -> String {
+ self.room.name()
+ }
+
+ pub async fn sid(&self) -> String {
+ self.room.sid().await.to_string()
+ }
+
pub async fn publish_local_microphone_track(
&self,
user_name: String,
diff --git a/crates/livekit_client/src/test.rs b/crates/livekit_client/src/test.rs
index fd316359820..a8222b9a18b 100644
--- a/crates/livekit_client/src/test.rs
+++ b/crates/livekit_client/src/test.rs
@@ -714,6 +714,14 @@ impl Room {
self.0.lock().token.clone()
}
+ pub fn name(&self) -> String {
+ "test_room".to_string()
+ }
+
+ pub async fn sid(&self) -> String {
+ "RM_test_session".to_string()
+ }
+
pub fn play_remote_audio_track(
&self,
_track: &RemoteAudioTrack,
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs
index aa100550749..d5a1c3a291c 100644
--- a/crates/workspace/src/workspace.rs
+++ b/crates/workspace/src/workspace.rs
@@ -7236,7 +7236,9 @@ actions!(
/// Shares the current project with collaborators.
ShareProject,
/// Shares your screen with collaborators.
- ScreenShare
+ ScreenShare,
+ /// Copies the current room name and session id for debugging purposes.
+ CopyRoomId,
]
);
actions!(