Skip to content

Commit 3d58738

Browse files
authored
collab: Add action to copy room id (#44004)
Adds a `collab: copy room id` action which copies the live kit room name and session ID to the clipboard. Release Notes: - N/A
1 parent 2db237a commit 3d58738

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

crates/call/src/call_impl/room.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,16 @@ impl Room {
524524
self.id
525525
}
526526

527+
pub fn room_id(&self) -> impl Future<Output = Option<String>> + 'static {
528+
let room = self.live_kit.as_ref().map(|lk| lk.room.clone());
529+
async move {
530+
let room = room?;
531+
let sid = room.sid().await;
532+
let name = room.name();
533+
Some(format!("{} (sid: {sid})", name))
534+
}
535+
}
536+
527537
pub fn status(&self) -> RoomStatus {
528538
self.status
529539
}

crates/collab_ui/src/collab_panel.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use ui::{
3737
};
3838
use util::{ResultExt, TryFutureExt, maybe};
3939
use workspace::{
40-
Deafen, LeaveCall, Mute, OpenChannelNotes, ScreenShare, ShareProject, Workspace,
40+
CopyRoomId, Deafen, LeaveCall, Mute, OpenChannelNotes, ScreenShare, ShareProject, Workspace,
4141
dock::{DockPosition, Panel, PanelEvent},
4242
notifications::{DetachAndPromptErr, NotifyResultExt},
4343
};
@@ -128,6 +128,32 @@ pub fn init(cx: &mut App) {
128128
workspace.register_action(|_, _: &LeaveCall, window, cx| {
129129
CollabPanel::leave_call(window, cx);
130130
});
131+
workspace.register_action(|workspace, _: &CopyRoomId, window, cx| {
132+
use workspace::notifications::{NotificationId, NotifyTaskExt as _};
133+
134+
struct RoomIdCopiedToast;
135+
136+
if let Some(room) = ActiveCall::global(cx).read(cx).room() {
137+
let romo_id_fut = room.read(cx).room_id();
138+
cx.spawn(async move |workspace, cx| {
139+
let room_id = romo_id_fut.await.context("Failed to get livekit room")?;
140+
workspace.update(cx, |workspace, cx| {
141+
cx.write_to_clipboard(ClipboardItem::new_string(room_id));
142+
workspace.show_toast(
143+
workspace::Toast::new(
144+
NotificationId::unique::<RoomIdCopiedToast>(),
145+
"Room ID copied to clipboard",
146+
)
147+
.autohide(),
148+
cx,
149+
);
150+
})
151+
})
152+
.detach_and_notify_err(window, cx);
153+
} else {
154+
workspace.show_error(&"There’s no active call; join one first.", cx);
155+
}
156+
});
131157
workspace.register_action(|workspace, _: &ShareProject, window, cx| {
132158
let project = workspace.project().clone();
133159
println!("{project:?}");

crates/livekit_client/src/livekit_client.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ impl Room {
9898
self.room.connection_state()
9999
}
100100

101+
pub fn name(&self) -> String {
102+
self.room.name()
103+
}
104+
105+
pub async fn sid(&self) -> String {
106+
self.room.sid().await.to_string()
107+
}
108+
101109
pub async fn publish_local_microphone_track(
102110
&self,
103111
user_name: String,

crates/livekit_client/src/test.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,14 @@ impl Room {
714714
self.0.lock().token.clone()
715715
}
716716

717+
pub fn name(&self) -> String {
718+
"test_room".to_string()
719+
}
720+
721+
pub async fn sid(&self) -> String {
722+
"RM_test_session".to_string()
723+
}
724+
717725
pub fn play_remote_audio_track(
718726
&self,
719727
_track: &RemoteAudioTrack,

crates/workspace/src/workspace.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7236,7 +7236,9 @@ actions!(
72367236
/// Shares the current project with collaborators.
72377237
ShareProject,
72387238
/// Shares your screen with collaborators.
7239-
ScreenShare
7239+
ScreenShare,
7240+
/// Copies the current room name and session id for debugging purposes.
7241+
CopyRoomId,
72407242
]
72417243
);
72427244
actions!(

0 commit comments

Comments
 (0)