fix(calls): consult transfer shows the consult call and transfers the consulted leg
- Consult call becomes the call view; the first call is held aside. Banner "<name> is on hold" with Transfer and Resume <first name>. - Transfer replaces the consulted person's roster leg (callLinks.replacement + replacementTargetParticipantId), as Teams web consultTransfer does. The acceptance link of our mixer call is only a fallback. - Held caller hangs up: the consult call keeps going as a normal call. Consulted person hangs up: back to the held call. Transfer done: we leave the consult call. - Transfer completion code and subCode land in the timeline; each answer settles the oldest open transfer in the report. - Consult call gets its own call report. - Demo scene "consult" and a layout guard screen for the banner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -123,6 +123,7 @@ pub struct AppState {
123
123
pub profiles: ProfileCache,
124
124
pub profile_request: Option<ProfileRequest>,
125
125
pub call: Option<ActiveCall>,
126
pub held_call: Option<ActiveCall>,
126
127
pub call_media: Option<Entity<CallMedia>>,
127
128
pub call_launcher: Option<Arc<CallLauncher>>,
128
129
pub call_count: u64,
@@ -236,6 +237,7 @@ impl AppState {
236
237
profiles: ProfileCache::new(),
237
238
profile_request: None,
238
239
call: None,
240
held_call: None,
239
241
call_media: None,
240
242
call_launcher: None,
241
243
call_count: 0,
@@ -123,6 +123,7 @@ pub struct AppState {123
pub profiles: ProfileCache,123
pub profiles: ProfileCache,124
pub profile_request: Option<ProfileRequest>,124
pub profile_request: Option<ProfileRequest>,125
pub call: Option<ActiveCall>,125
pub call: Option<ActiveCall>,126
pub held_call: Option<ActiveCall>,126
pub call_media: Option<Entity<CallMedia>>,127
pub call_media: Option<Entity<CallMedia>>,127
pub call_launcher: Option<Arc<CallLauncher>>,128
pub call_launcher: Option<Arc<CallLauncher>>,128
pub call_count: u64,129
pub call_count: u64,@@ -236,6 +237,7 @@ impl AppState {236
profiles: ProfileCache::new(),237
profiles: ProfileCache::new(),237
profile_request: None,238
profile_request: None,238
call: None,239
call: None,240
held_call: None,239
call_media: None,241
call_media: None,240
call_launcher: None,242
call_launcher: None,241
call_count: 0,243
call_count: 0,@@ -14,10 +14,10 @@ use super::demo::{
14
14
DemoCall, DemoScene, demo_caller, demo_guests, demo_ring, demo_video_ring, start_demo_call,
15
15
start_demo_scene_call,
16
16
};
17
use super::features::room_closed_move;
17
use super::features::{TransferCandidate, room_closed_move};
18
18
use super::media::CallMedia;
19
19
use super::mic::save_mic;
20
use super::model::{ActiveCall, CallKind, CallModel, ended_notice};
20
use super::model::{ActiveCall, CallKind, CallModel, ConsultTransfer, ended_notice};
21
21
use super::prejoin::{DemoMeeting, MeetingJoin};
22
22
use super::report::{
23
23
CallRecorder, OwnIdentity, SETTING_META_KEY, SharedRecorder, report_directory, save_report, shared,
@@ -35,6 +35,8 @@ const READ_ONLY_NOTICE: &str = "Calls are off in read-only mode";
35
35
const NOT_CALLABLE_NOTICE: &str = "This chat cannot be called";
36
36
pub(super) const MEETING_UNAVAILABLE_NOTICE: &str = "This meeting cannot be joined";
37
37
const ANSWER_FAILED_NOTICE: &str = "Could not answer the call";
38
const CONSULT_ENDED_NOTICE: &str = "The consultation ended";
39
const DEMO_CONSULT_TARGET: (&str, &str) = ("8:orgid:demo-guest-1", "Jonas Ortega");
38
40
const MEETING_KIND: &str = "meeting";
39
41
const DEMO_LOBBY_MEETING: &str = "demo-chat-meeting-retro";
40
42
const DEMO_CROWD: usize = 11;
@@ -75,6 +77,15 @@ fn camera_meta(choice: &DeviceChoice) -> &str {
75
77
}
76
78
}
77
79
80
fn demo_consult_target() -> TransferCandidate {
81
TransferCandidate {
82
mri: DEMO_CONSULT_TARGET.0.to_owned(),
83
name: DEMO_CONSULT_TARGET.1.to_owned(),
84
user_id: None,
85
chat_id: "demo-chat-jonas".to_owned(),
86
}
87
}
88
78
89
fn now_unix() -> i64 {
79
90
chrono::Utc::now().timestamp()
80
91
}
@@ -357,15 +368,15 @@ impl AppState {
357
368
cx.background_executor().timer(TIMER_REFRESH).await;
358
369
ticks += 1;
359
370
let running = this.update(cx, |state, cx| {
360
let running = state.call.as_ref().is_some_and(|call| call.id == call_id);
361
if running {
371
let visible = state.call.as_ref().is_some_and(|call| call.id == call_id);
372
if visible {
362
373
if ticks.is_multiple_of(SHARE_SOURCES_EVERY_TICKS) {
363
374
state.refresh_share_sources();
364
375
}
365
376
state.tick_call_layout(cx);
366
377
CallMedia::changed(&state.call_media, cx);
367
378
}
368
running
379
visible || state.is_held_call(call_id)
369
380
});
370
381
if !running.unwrap_or(false) {
371
382
return;
@@ -378,8 +389,9 @@ impl AppState {
378
389
fn end_orphaned_call(&mut self, call_id: u64, cx: &mut Context<Self>) {
379
390
let still_open = self
380
391
.call
381
.as_ref()
382
.is_some_and(|call| call.id == call_id && call.model.is_active());
392
.iter()
393
.chain(&self.held_call)
394
.any(|call| call.id == call_id && call.model.is_active());
383
395
if still_open {
384
396
let reason = EndReason::Failed("The call stopped unexpectedly".to_owned());
385
397
self.apply_call_update(call_id, CallUpdate::State(CallState::Ended { reason }), cx);
@@ -415,6 +427,10 @@ impl AppState {
415
427
cx: &mut Context<Self>,
416
428
) {
417
429
let update = self.with_known_names(update);
430
if self.is_held_call(call_id) {
431
self.apply_held_call_update(update, cx);
432
return;
433
}
418
434
let media = self.call_media.clone();
419
435
let Some(call) = self.call.as_mut().filter(|call| call.id == call_id) else {
420
436
return;
@@ -453,6 +469,13 @@ impl AppState {
453
469
cx.notify();
454
470
return;
455
471
}
472
CallUpdate::ReplacementLink(replacement) => {
473
if let Some(consult) = call.consult.as_mut() {
474
consult.replacement = Some(replacement);
475
cx.notify();
476
}
477
return;
478
}
456
479
CallUpdate::MeetingOptionsSaved(result) => {
457
480
if call.options_dialog.as_mut().is_some_and(|dialog| dialog.saved(result)) {
458
481
call.options_dialog = None;
@@ -492,20 +515,29 @@ impl AppState {
492
515
return;
493
516
};
494
517
let elapsed = call.model.elapsed(Instant::now());
495
let notice = ended_notice(&reason, elapsed, &call.model.peer_name);
518
let consult = call.consult.take();
519
let notice = match &consult {
520
Some(consult) if consult.transfer == ConsultTransfer::Done => {
521
format!("Call transferred to {}", consult.target.1)
522
}
523
Some(_) if self.held_call.is_some() => CONSULT_ENDED_NOTICE.to_owned(),
524
_ => ended_notice(&reason, elapsed, &call.model.peer_name),
525
};
526
let back_to_held = consult
527
.as_ref()
528
.is_some_and(|consult| consult.transfer != ConsultTransfer::Done);
496
529
let next_move = call
497
530
.pending_move
498
531
.take()
499
532
.or_else(|| room_closed_move(call, &reason));
500
let consult = call.consult.take();
501
533
call.pictures.clear(cx);
502
534
if let Some(thread) = call.chat_thread() {
503
535
crate::agent_api::clear_captions(thread, cx);
504
536
}
505
537
self.call = None;
506
538
self.transcript_panel = None;
507
if let Some(consult) = consult {
508
let _ = consult.commands.send(CallCommand::Hangup);
539
if back_to_held {
540
self.call = self.held_call.take();
509
541
}
510
542
match next_move {
511
543
Some(next_move) => self.join_moved_call(next_move, cx),
@@ -1059,6 +1091,14 @@ impl AppState {
1059
1091
if scene == DemoScene::Gallery {
1060
1092
self.queue_demo_bubbles(conversation_id, cx);
1061
1093
}
1094
if scene == DemoScene::Consult {
1095
if let Some(call) = self.call.as_mut() {
1096
call.model.apply(CallUpdate::State(CallState::Connected {
1097
since: Instant::now(),
1098
}));
1099
}
1100
self.start_consult(demo_consult_target(), cx);
1101
}
1062
1102
}
1063
1103
1064
1104
fn signal_ring(&mut self, ring_id: u64, signal: RingSignal, cx: &mut Context<Self>) {
@@ -1282,7 +1322,7 @@ mod tests {
1282
1322
use crate::call::{CaptionPosition, CaptionSize, RecordAction, ViewSettings};
1283
1323
use crate::call::demo::demo_ring;
1284
1324
use crate::call::features::room_closed_move;
1285
use crate::call::model::{BreakoutState, ConsultCall};
1325
use crate::call::model::BreakoutState;
1286
1326
use crate::data::Person;
1287
1327
1288
1328
fn app_with_call(cx: &mut TestAppContext) -> Entity<AppState> {
@@ -1876,7 +1916,7 @@ mod tests {
1876
1916
}
1877
1917
1878
1918
#[gpui_kit::test]
1879
fn a_blind_transfer_names_the_target_and_a_consulted_one_carries_the_replacement_link(
1919
fn a_blind_transfer_names_the_target(
1880
1920
cx: &mut TestAppContext,
1881
1921
) {
1882
1922
let (app, mut control) = app_with_commands(cx, live_one_to_one(), None);
@@ -1895,37 +1935,6 @@ mod tests {
1895
1935
replaces: None
1896
1936
})
1897
1937
);
1898
let (consulting, mut consult_control) = app_with_commands(cx, live_one_to_one(), None);
1899
let (consult_handle, _consult_updates) = call_channel();
1900
cx.update(|cx| {
1901
consulting.update(cx, |state, cx| {
1902
state.call.as_mut().unwrap().consult = Some(ConsultCall {
1903
id: 8,
1904
target: ("8:orgid:ana".into(), "Ana".into()),
1905
commands: consult_handle.commands,
1906
state: CallState::Connecting,
1907
replacement: Some("https://cc.skype.com/replacement".into()),
1908
transferring: false,
1909
});
1910
state.transfer_consulted(cx);
1911
state.call.as_mut().unwrap().consult.as_mut().unwrap().state =
1912
CallState::Connected {
1913
since: Instant::now(),
1914
};
1915
state.transfer_consulted(cx);
1916
})
1917
});
1918
assert_eq!(
1919
consult_control.try_recv_command(),
1920
Some(CallCommand::Transfer {
1921
target: calling::Callee {
1922
mri: "8:orgid:ana".into(),
1923
display_name: "Ana".into()
1924
},
1925
replaces: Some("https://cc.skype.com/replacement".into()),
1926
})
1927
);
1928
assert_eq!(consult_control.try_recv_command(), None);
1929
1938
}
1930
1939
1931
1940
#[gpui_kit::test]
@@ -14,10 +14,10 @@ use super::demo::{14
DemoCall, DemoScene, demo_caller, demo_guests, demo_ring, demo_video_ring, start_demo_call,14
DemoCall, DemoScene, demo_caller, demo_guests, demo_ring, demo_video_ring, start_demo_call,15
start_demo_scene_call,15
start_demo_scene_call,16
};16
};17
use super::features::room_closed_move;17
use super::features::{TransferCandidate, room_closed_move};18
use super::media::CallMedia;18
use super::media::CallMedia;19
use super::mic::save_mic;19
use super::mic::save_mic;20
use super::model::{ActiveCall, CallKind, CallModel, ended_notice};20
use super::model::{ActiveCall, CallKind, CallModel, ConsultTransfer, ended_notice};21
use super::prejoin::{DemoMeeting, MeetingJoin};21
use super::prejoin::{DemoMeeting, MeetingJoin};22
use super::report::{22
use super::report::{23
CallRecorder, OwnIdentity, SETTING_META_KEY, SharedRecorder, report_directory, save_report, shared,23
CallRecorder, OwnIdentity, SETTING_META_KEY, SharedRecorder, report_directory, save_report, shared,@@ -35,6 +35,8 @@ const READ_ONLY_NOTICE: &str = "Calls are off in read-only mode";35
const NOT_CALLABLE_NOTICE: &str = "This chat cannot be called";35
const NOT_CALLABLE_NOTICE: &str = "This chat cannot be called";36
pub(super) const MEETING_UNAVAILABLE_NOTICE: &str = "This meeting cannot be joined";36
pub(super) const MEETING_UNAVAILABLE_NOTICE: &str = "This meeting cannot be joined";37
const ANSWER_FAILED_NOTICE: &str = "Could not answer the call";37
const ANSWER_FAILED_NOTICE: &str = "Could not answer the call";38
const CONSULT_ENDED_NOTICE: &str = "The consultation ended";39
const DEMO_CONSULT_TARGET: (&str, &str) = ("8:orgid:demo-guest-1", "Jonas Ortega");38
const MEETING_KIND: &str = "meeting";40
const MEETING_KIND: &str = "meeting";39
const DEMO_LOBBY_MEETING: &str = "demo-chat-meeting-retro";41
const DEMO_LOBBY_MEETING: &str = "demo-chat-meeting-retro";40
const DEMO_CROWD: usize = 11;42
const DEMO_CROWD: usize = 11;@@ -75,6 +77,15 @@ fn camera_meta(choice: &DeviceChoice) -> &str {75
}77
}76
}78
}77
79
80
fn demo_consult_target() -> TransferCandidate {81
TransferCandidate {82
mri: DEMO_CONSULT_TARGET.0.to_owned(),83
name: DEMO_CONSULT_TARGET.1.to_owned(),84
user_id: None,85
chat_id: "demo-chat-jonas".to_owned(),86
}87
}88
78
fn now_unix() -> i64 {89
fn now_unix() -> i64 {79
chrono::Utc::now().timestamp()90
chrono::Utc::now().timestamp()80
}91
}@@ -357,15 +368,15 @@ impl AppState {357
cx.background_executor().timer(TIMER_REFRESH).await;368
cx.background_executor().timer(TIMER_REFRESH).await;358
ticks += 1;369
ticks += 1;359
let running = this.update(cx, |state, cx| {370
let running = this.update(cx, |state, cx| {360
let running = state.call.as_ref().is_some_and(|call| call.id == call_id);371
let visible = state.call.as_ref().is_some_and(|call| call.id == call_id);361
if running {372
if visible {362
if ticks.is_multiple_of(SHARE_SOURCES_EVERY_TICKS) {373
if ticks.is_multiple_of(SHARE_SOURCES_EVERY_TICKS) {363
state.refresh_share_sources();374
state.refresh_share_sources();364
}375
}365
state.tick_call_layout(cx);376
state.tick_call_layout(cx);366
CallMedia::changed(&state.call_media, cx);377
CallMedia::changed(&state.call_media, cx);367
}378
}368
running379
visible || state.is_held_call(call_id)369
});380
});370
if !running.unwrap_or(false) {381
if !running.unwrap_or(false) {371
return;382
return;@@ -378,8 +389,9 @@ impl AppState {378
fn end_orphaned_call(&mut self, call_id: u64, cx: &mut Context<Self>) {389
fn end_orphaned_call(&mut self, call_id: u64, cx: &mut Context<Self>) {379
let still_open = self390
let still_open = self380
.call391
.call381
.as_ref()392
.iter()382
.is_some_and(|call| call.id == call_id && call.model.is_active());393
.chain(&self.held_call)394
.any(|call| call.id == call_id && call.model.is_active());383
if still_open {395
if still_open {384
let reason = EndReason::Failed("The call stopped unexpectedly".to_owned());396
let reason = EndReason::Failed("The call stopped unexpectedly".to_owned());385
self.apply_call_update(call_id, CallUpdate::State(CallState::Ended { reason }), cx);397
self.apply_call_update(call_id, CallUpdate::State(CallState::Ended { reason }), cx);@@ -415,6 +427,10 @@ impl AppState {415
cx: &mut Context<Self>,427
cx: &mut Context<Self>,416
) {428
) {417
let update = self.with_known_names(update);429
let update = self.with_known_names(update);430
if self.is_held_call(call_id) {431
self.apply_held_call_update(update, cx);432
return;433
}418
let media = self.call_media.clone();434
let media = self.call_media.clone();419
let Some(call) = self.call.as_mut().filter(|call| call.id == call_id) else {435
let Some(call) = self.call.as_mut().filter(|call| call.id == call_id) else {420
return;436
return;@@ -453,6 +469,13 @@ impl AppState {453
cx.notify();469
cx.notify();454
return;470
return;455
}471
}472
CallUpdate::ReplacementLink(replacement) => {473
if let Some(consult) = call.consult.as_mut() {474
consult.replacement = Some(replacement);475
cx.notify();476
}477
return;478
}456
CallUpdate::MeetingOptionsSaved(result) => {479
CallUpdate::MeetingOptionsSaved(result) => {457
if call.options_dialog.as_mut().is_some_and(|dialog| dialog.saved(result)) {480
if call.options_dialog.as_mut().is_some_and(|dialog| dialog.saved(result)) {458
call.options_dialog = None;481
call.options_dialog = None;@@ -492,20 +515,29 @@ impl AppState {492
return;515
return;493
};516
};494
let elapsed = call.model.elapsed(Instant::now());517
let elapsed = call.model.elapsed(Instant::now());495
let notice = ended_notice(&reason, elapsed, &call.model.peer_name);518
let consult = call.consult.take();519
let notice = match &consult {520
Some(consult) if consult.transfer == ConsultTransfer::Done => {521
format!("Call transferred to {}", consult.target.1)522
}523
Some(_) if self.held_call.is_some() => CONSULT_ENDED_NOTICE.to_owned(),524
_ => ended_notice(&reason, elapsed, &call.model.peer_name),525
};526
let back_to_held = consult527
.as_ref()528
.is_some_and(|consult| consult.transfer != ConsultTransfer::Done);496
let next_move = call529
let next_move = call497
.pending_move530
.pending_move498
.take()531
.take()499
.or_else(|| room_closed_move(call, &reason));532
.or_else(|| room_closed_move(call, &reason));500
let consult = call.consult.take();501
call.pictures.clear(cx);533
call.pictures.clear(cx);502
if let Some(thread) = call.chat_thread() {534
if let Some(thread) = call.chat_thread() {503
crate::agent_api::clear_captions(thread, cx);535
crate::agent_api::clear_captions(thread, cx);504
}536
}505
self.call = None;537
self.call = None;506
self.transcript_panel = None;538
self.transcript_panel = None;507
if let Some(consult) = consult {539
if back_to_held {508
let _ = consult.commands.send(CallCommand::Hangup);540
self.call = self.held_call.take();509
}541
}510
match next_move {542
match next_move {511
Some(next_move) => self.join_moved_call(next_move, cx),543
Some(next_move) => self.join_moved_call(next_move, cx),@@ -1059,6 +1091,14 @@ impl AppState {1059
if scene == DemoScene::Gallery {1091
if scene == DemoScene::Gallery {1060
self.queue_demo_bubbles(conversation_id, cx);1092
self.queue_demo_bubbles(conversation_id, cx);1061
}1093
}1094
if scene == DemoScene::Consult {1095
if let Some(call) = self.call.as_mut() {1096
call.model.apply(CallUpdate::State(CallState::Connected {1097
since: Instant::now(),1098
}));1099
}1100
self.start_consult(demo_consult_target(), cx);1101
}1062
}1102
}1063
1103
1064
fn signal_ring(&mut self, ring_id: u64, signal: RingSignal, cx: &mut Context<Self>) {1104
fn signal_ring(&mut self, ring_id: u64, signal: RingSignal, cx: &mut Context<Self>) {@@ -1282,7 +1322,7 @@ mod tests {1282
use crate::call::{CaptionPosition, CaptionSize, RecordAction, ViewSettings};1322
use crate::call::{CaptionPosition, CaptionSize, RecordAction, ViewSettings};1283
use crate::call::demo::demo_ring;1323
use crate::call::demo::demo_ring;1284
use crate::call::features::room_closed_move;1324
use crate::call::features::room_closed_move;1285
use crate::call::model::{BreakoutState, ConsultCall};1325
use crate::call::model::BreakoutState;1286
use crate::data::Person;1326
use crate::data::Person;1287
1327
1288
fn app_with_call(cx: &mut TestAppContext) -> Entity<AppState> {1328
fn app_with_call(cx: &mut TestAppContext) -> Entity<AppState> {@@ -1876,7 +1916,7 @@ mod tests {1876
}1916
}1877
1917
1878
#[gpui_kit::test]1918
#[gpui_kit::test]1879
fn a_blind_transfer_names_the_target_and_a_consulted_one_carries_the_replacement_link(1919
fn a_blind_transfer_names_the_target(1880
cx: &mut TestAppContext,1920
cx: &mut TestAppContext,1881
) {1921
) {1882
let (app, mut control) = app_with_commands(cx, live_one_to_one(), None);1922
let (app, mut control) = app_with_commands(cx, live_one_to_one(), None);@@ -1895,37 +1935,6 @@ mod tests {1895
replaces: None1935
replaces: None1896
})1936
})1897
);1937
);1898
let (consulting, mut consult_control) = app_with_commands(cx, live_one_to_one(), None);1899
let (consult_handle, _consult_updates) = call_channel();1900
cx.update(|cx| {1901
consulting.update(cx, |state, cx| {1902
state.call.as_mut().unwrap().consult = Some(ConsultCall {1903
id: 8,1904
target: ("8:orgid:ana".into(), "Ana".into()),1905
commands: consult_handle.commands,1906
state: CallState::Connecting,1907
replacement: Some("https://cc.skype.com/replacement".into()),1908
transferring: false,1909
});1910
state.transfer_consulted(cx);1911
state.call.as_mut().unwrap().consult.as_mut().unwrap().state =1912
CallState::Connected {1913
since: Instant::now(),1914
};1915
state.transfer_consulted(cx);1916
})1917
});1918
assert_eq!(1919
consult_control.try_recv_command(),1920
Some(CallCommand::Transfer {1921
target: calling::Callee {1922
mri: "8:orgid:ana".into(),1923
display_name: "Ana".into()1924
},1925
replaces: Some("https://cc.skype.com/replacement".into()),1926
})1927
);1928
assert_eq!(consult_control.try_recv_command(), None);1929
}1938
}1930
1939
1931
#[gpui_kit::test]1940
#[gpui_kit::test]@@ -0,0 +1,373 @@
1
use calling::{CallCommand, CallHandle, CallSpec, CallUpdate, Callee};
2
use gpui_kit::*;
3
4
use super::demo::{DemoCall, start_demo_call};
5
use super::features::TransferCandidate;
6
use super::model::{ActiveCall, CallModel, ConsultCall, ConsultTransfer};
7
use crate::app_state::{AppEvent, AppState};
8
9
const CONSULT_REPORT_NOTE: &str = "consult call, the first call is on hold";
10
11
fn send_to(call: &ActiveCall, command: CallCommand) {
12
if let Some(report) = &call.report {
13
report.borrow_mut().command(&command);
14
}
15
let _ = call.commands.send(command);
16
}
17
18
impl AppState {
19
pub fn start_consult(&mut self, target: TransferCandidate, cx: &mut Context<Self>) {
20
self.close_transfer_picker(cx);
21
if !self.can_transfer_call() {
22
return;
23
}
24
let handle = if self.mode.demo {
25
Some(start_demo_call(DemoCall::People(vec![(
26
target.mri.clone(),
27
target.name.clone(),
28
)])))
29
} else {
30
self.call_launcher.clone().map(|launcher| {
31
launcher.start_consult(CallSpec::People {
32
callees: vec![Callee {
33
mri: target.mri.clone(),
34
display_name: target.name.clone(),
35
}],
36
thread_id: target.chat_id.clone(),
37
})
38
})
39
};
40
let Some(handle) = handle else {
41
self.raise_notice("Not connected to Teams yet".to_owned(), None, cx);
42
return;
43
};
44
self.begin_consult(target, handle, cx);
45
}
46
47
fn begin_consult(&mut self, target: TransferCandidate, handle: CallHandle, cx: &mut Context<Self>) {
48
let callee = (target.mri.clone(), target.name.clone());
49
self.note_call_feature("consult", format!("start with {}", target.mri));
50
self.send_call_command(CallCommand::Hold(true));
51
let Some(held) = self.call.take() else {
52
return;
53
};
54
let held_name = held.model.peer_name.clone();
55
self.held_call = Some(held);
56
if let Some(user_id) = target.user_id.clone() {
57
self.request_avatars(vec![user_id], cx);
58
}
59
let model = CallModel::people(&target.name, std::slice::from_ref(&callee));
60
self.begin_call(handle, model, Some(target.chat_id), cx);
61
if let Some(call) = self.call.as_mut() {
62
call.consult = Some(ConsultCall::new(callee, held_name));
63
}
64
self.note_call_feature("consult", CONSULT_REPORT_NOTE.to_owned());
65
cx.notify();
66
}
67
68
pub fn transfer_consulted(&mut self, cx: &mut Context<Self>) {
69
let (Some(call), Some(held)) = (self.call.as_mut(), self.held_call.as_ref()) else {
70
return;
71
};
72
let model = &call.model;
73
let Some(consult) = call
74
.consult
75
.as_mut()
76
.filter(|consult| consult.ready_to_transfer(model))
77
else {
78
return;
79
};
80
consult.transfer = ConsultTransfer::Pending;
81
let (mri, display_name) = consult.target.clone();
82
send_to(
83
held,
84
CallCommand::Transfer {
85
target: Callee { mri, display_name },
86
replaces: consult.replacement.clone(),
87
},
88
);
89
cx.notify();
90
}
91
92
pub fn resume_held_call(&mut self, _cx: &mut Context<Self>) {
93
let (Some(call), Some(held)) = (self.call.as_ref(), self.held_call.as_ref()) else {
94
return;
95
};
96
if call.consult.is_none() {
97
return;
98
}
99
send_to(held, CallCommand::Hold(false));
100
send_to(call, CallCommand::Hangup);
101
}
102
103
pub(super) fn is_held_call(&self, call_id: u64) -> bool {
104
self.held_call.as_ref().is_some_and(|held| held.id == call_id)
105
}
106
107
pub(super) fn apply_held_call_update(&mut self, update: CallUpdate, cx: &mut Context<Self>) {
108
let Some(held) = self.held_call.as_mut() else {
109
return;
110
};
111
match update {
112
CallUpdate::Notice(text) => {
113
self.raise_notice(text, None, cx);
114
return;
115
}
116
CallUpdate::TransferResult { succeeded } => {
117
self.settle_consult_transfer(succeeded);
118
cx.notify();
119
return;
120
}
121
CallUpdate::VideoReady
122
| CallUpdate::Levels { .. }
123
| CallUpdate::Stats { .. }
124
| CallUpdate::Sample(_)
125
| CallUpdate::Health(_) => return,
126
other => held.model.apply(other),
127
}
128
if held.model.ended_reason().is_none() {
129
return;
130
}
131
let Some(mut ended) = self.held_call.take() else {
132
return;
133
};
134
ended.pictures.clear(cx);
135
let consult = self.call.as_mut().and_then(|call| {
136
let transferred = call
137
.consult
138
.as_ref()
139
.is_some_and(|consult| consult.transfer == ConsultTransfer::Done);
140
if transferred { None } else { call.consult.take() }
141
});
142
if let Some(consult) = consult {
143
self.raise_notice(format!("{} hung up", consult.held_name), None, cx);
144
}
145
self.refresh_call_history_after_call(cx);
146
cx.emit(AppEvent::Call);
147
cx.notify();
148
}
149
150
fn settle_consult_transfer(&mut self, succeeded: bool) {
151
let Some(call) = self.call.as_mut() else {
152
return;
153
};
154
let Some(consult) = call.consult.as_mut() else {
155
return;
156
};
157
consult.transfer = if succeeded {
158
ConsultTransfer::Done
159
} else {
160
ConsultTransfer::Idle
161
};
162
if succeeded {
163
send_to(call, CallCommand::Hangup);
164
}
165
}
166
}
167
168
#[cfg(test)]
169
mod tests {
170
use std::sync::Arc;
171
use std::time::Instant;
172
173
use calling::{
174
CallCommand, CallControl, CallState, CallUpdate, Callee, EndReason, HoldState, Replacement,
175
call_channel,
176
};
177
use gpui_kit::{AppContext as _, Entity, TestAppContext};
178
use store::Store;
179
180
use super::{ActiveCall, CallModel, ConsultCall, TransferCandidate};
181
use crate::app_state::{AppState, Mode};
182
183
const HELD_ID: u64 = 7;
184
const CONSULT_ID: u64 = 8;
185
186
fn connected(name: &str, mri: &str) -> CallModel {
187
let mut model = CallModel::people(name, &[(mri.into(), name.into())]);
188
model.apply(CallUpdate::State(CallState::Connected {
189
since: Instant::now(),
190
}));
191
model
192
}
193
194
fn consulting(cx: &mut TestAppContext) -> (Entity<AppState>, CallControl, CallControl) {
195
cx.update(gpui_kit::init);
196
let store = Arc::new(Store::open_in_memory().unwrap());
197
let app = cx.update(|cx| cx.new(|_| AppState::new(store, Mode::default())));
198
let (held_handle, held_control) = call_channel();
199
let (consult_handle, consult_control) = call_channel();
200
cx.update(|cx| {
201
app.update(cx, |state, _| {
202
let mut held_model = connected("Chris", "8:orgid:chris");
203
held_model.apply(CallUpdate::Hold(HoldState::Local));
204
state.held_call = Some(ActiveCall::new(
205
HELD_ID,
206
held_model,
207
held_handle.commands,
208
None,
209
held_handle.video,
210
));
211
let mut consult = ActiveCall::new(
212
CONSULT_ID,
213
connected("Ana", "8:orgid:ana"),
214
consult_handle.commands,
215
None,
216
consult_handle.video,
217
);
218
consult.consult = Some(ConsultCall::new(
219
("8:orgid:ana".into(), "Ana".into()),
220
"Chris".into(),
221
));
222
state.call = Some(consult);
223
})
224
});
225
(app, held_control, consult_control)
226
}
227
228
fn ended() -> CallUpdate {
229
CallUpdate::State(CallState::Ended {
230
reason: EndReason::LocalHangup,
231
})
232
}
233
234
fn leg() -> Replacement {
235
Replacement {
236
link: "https://cc/ana/replacement".into(),
237
participant_id: Some("leg-ana".into()),
238
}
239
}
240
241
#[gpui_kit::test]
242
fn consulting_holds_the_first_call_and_shows_the_consult_call(cx: &mut TestAppContext) {
243
cx.update(gpui_kit::init);
244
let store = Arc::new(Store::open_in_memory().unwrap());
245
let app = cx.update(|cx| cx.new(|_| AppState::new(store, Mode::default())));
246
let (held_handle, mut held_control) = call_channel();
247
let (consult_handle, _consult_control) = call_channel();
248
let target = TransferCandidate {
249
mri: "8:orgid:ana".into(),
250
name: "Ana".into(),
251
user_id: Some("ana".into()),
252
chat_id: "19:ana".into(),
253
};
254
cx.update(|cx| {
255
app.update(cx, |state, cx| {
256
state.call = Some(ActiveCall::new(
257
HELD_ID,
258
connected("Chris", "8:orgid:chris"),
259
held_handle.commands,
260
None,
261
held_handle.video,
262
));
263
state.begin_consult(target, consult_handle, cx);
264
assert_eq!(state.held_call.as_ref().unwrap().id, HELD_ID);
265
let call = state.call.as_ref().unwrap();
266
assert_ne!(call.id, HELD_ID);
267
assert_eq!(call.model.peer_name, "Ana");
268
assert_eq!(call.consult.as_ref().unwrap().banner_text(), "Chris is on hold");
269
})
270
});
271
assert_eq!(held_control.try_recv_command(), Some(CallCommand::Hold(true)));
272
}
273
274
#[gpui_kit::test]
275
fn the_transfer_goes_to_the_held_call_with_the_consulted_persons_leg(cx: &mut TestAppContext) {
276
let (app, mut held_control, mut consult_control) = consulting(cx);
277
cx.update(|cx| {
278
app.update(cx, |state, cx| {
279
state.transfer_consulted(cx);
280
state.apply_call_update(CONSULT_ID, CallUpdate::ReplacementLink(leg()), cx);
281
state.transfer_consulted(cx);
282
state.transfer_consulted(cx);
283
})
284
});
285
assert_eq!(
286
held_control.try_recv_command(),
287
Some(CallCommand::Transfer {
288
target: Callee {
289
mri: "8:orgid:ana".into(),
290
display_name: "Ana".into()
291
},
292
replaces: Some(leg()),
293
})
294
);
295
assert_eq!(held_control.try_recv_command(), None);
296
assert_eq!(consult_control.try_recv_command(), None);
297
}
298
299
#[gpui_kit::test]
300
fn a_failed_transfer_can_be_tried_again_and_a_completed_one_ends_both_calls(
301
cx: &mut TestAppContext,
302
) {
303
let (app, mut held_control, mut consult_control) = consulting(cx);
304
cx.update(|cx| {
305
app.update(cx, |state, cx| {
306
state.apply_call_update(CONSULT_ID, CallUpdate::ReplacementLink(leg()), cx);
307
state.transfer_consulted(cx);
308
state.apply_call_update(HELD_ID, CallUpdate::TransferResult { succeeded: false }, cx);
309
state.transfer_consulted(cx);
310
state.apply_call_update(HELD_ID, CallUpdate::TransferResult { succeeded: true }, cx);
311
state.apply_call_update(HELD_ID, ended(), cx);
312
assert!(state.held_call.is_none());
313
assert!(state.call.as_ref().unwrap().consult.is_some());
314
state.apply_call_update(CONSULT_ID, ended(), cx);
315
assert!(state.call.is_none());
316
assert_eq!(state.notice.as_ref().unwrap().text, "Call transferred to Ana");
317
})
318
});
319
assert!(matches!(held_control.try_recv_command(), Some(CallCommand::Transfer { .. })));
320
assert!(matches!(held_control.try_recv_command(), Some(CallCommand::Transfer { .. })));
321
assert_eq!(consult_control.try_recv_command(), Some(CallCommand::Hangup));
322
}
323
324
#[gpui_kit::test]
325
fn the_consult_call_keeps_going_when_the_held_caller_hangs_up(cx: &mut TestAppContext) {
326
let (app, _held_control, mut consult_control) = consulting(cx);
327
cx.update(|cx| {
328
app.update(cx, |state, cx| {
329
state.apply_call_update(HELD_ID, ended(), cx);
330
assert!(state.held_call.is_none());
331
let call = state.call.as_ref().expect("consult call stays");
332
assert_eq!(call.id, CONSULT_ID);
333
assert!(call.consult.is_none());
334
assert!(call.model.is_active());
335
assert_eq!(state.notice.as_ref().unwrap().text, "Chris hung up");
336
})
337
});
338
assert_eq!(consult_control.try_recv_command(), None);
339
}
340
341
#[gpui_kit::test]
342
fn the_held_call_comes_back_when_the_consult_ends_and_resume_ends_the_consult(
343
cx: &mut TestAppContext,
344
) {
345
let (app, mut held_control, mut consult_control) = consulting(cx);
346
cx.update(|cx| {
347
app.update(cx, |state, cx| {
348
state.resume_held_call(cx);
349
state.apply_call_update(CONSULT_ID, ended(), cx);
350
let call = state.call.as_ref().expect("held call is back");
351
assert_eq!(call.id, HELD_ID);
352
assert!(state.held_call.is_none());
353
assert_eq!(state.notice.as_ref().unwrap().text, "The consultation ended");
354
})
355
});
356
assert_eq!(held_control.try_recv_command(), Some(CallCommand::Hold(false)));
357
assert_eq!(consult_control.try_recv_command(), Some(CallCommand::Hangup));
358
}
359
360
#[gpui_kit::test]
361
fn held_call_updates_never_reach_the_visible_consult_call(cx: &mut TestAppContext) {
362
let (app, _held_control, _consult_control) = consulting(cx);
363
cx.update(|cx| {
364
app.update(cx, |state, cx| {
365
state.apply_call_update(HELD_ID, CallUpdate::Hold(HoldState::Active), cx);
366
assert_eq!(state.held_call.as_ref().unwrap().model.hold, HoldState::Active);
367
assert_eq!(state.call.as_ref().unwrap().model.hold, HoldState::Active);
368
assert_eq!(state.call.as_ref().unwrap().model.peer_name, "Ana");
369
assert!(!state.can_transfer_call());
370
})
371
});
372
}
373
}
@@ -0,0 +1,373 @@1
use calling::{CallCommand, CallHandle, CallSpec, CallUpdate, Callee};2
use gpui_kit::*;3
4
use super::demo::{DemoCall, start_demo_call};5
use super::features::TransferCandidate;6
use super::model::{ActiveCall, CallModel, ConsultCall, ConsultTransfer};7
use crate::app_state::{AppEvent, AppState};8
9
const CONSULT_REPORT_NOTE: &str = "consult call, the first call is on hold";10
11
fn send_to(call: &ActiveCall, command: CallCommand) {12
if let Some(report) = &call.report {13
report.borrow_mut().command(&command);14
}15
let _ = call.commands.send(command);16
}17
18
impl AppState {19
pub fn start_consult(&mut self, target: TransferCandidate, cx: &mut Context<Self>) {20
self.close_transfer_picker(cx);21
if !self.can_transfer_call() {22
return;23
}24
let handle = if self.mode.demo {25
Some(start_demo_call(DemoCall::People(vec![(26
target.mri.clone(),27
target.name.clone(),28
)])))29
} else {30
self.call_launcher.clone().map(|launcher| {31
launcher.start_consult(CallSpec::People {32
callees: vec![Callee {33
mri: target.mri.clone(),34
display_name: target.name.clone(),35
}],36
thread_id: target.chat_id.clone(),37
})38
})39
};40
let Some(handle) = handle else {41
self.raise_notice("Not connected to Teams yet".to_owned(), None, cx);42
return;43
};44
self.begin_consult(target, handle, cx);45
}46
47
fn begin_consult(&mut self, target: TransferCandidate, handle: CallHandle, cx: &mut Context<Self>) {48
let callee = (target.mri.clone(), target.name.clone());49
self.note_call_feature("consult", format!("start with {}", target.mri));50
self.send_call_command(CallCommand::Hold(true));51
let Some(held) = self.call.take() else {52
return;53
};54
let held_name = held.model.peer_name.clone();55
self.held_call = Some(held);56
if let Some(user_id) = target.user_id.clone() {57
self.request_avatars(vec![user_id], cx);58
}59
let model = CallModel::people(&target.name, std::slice::from_ref(&callee));60
self.begin_call(handle, model, Some(target.chat_id), cx);61
if let Some(call) = self.call.as_mut() {62
call.consult = Some(ConsultCall::new(callee, held_name));63
}64
self.note_call_feature("consult", CONSULT_REPORT_NOTE.to_owned());65
cx.notify();66
}67
68
pub fn transfer_consulted(&mut self, cx: &mut Context<Self>) {69
let (Some(call), Some(held)) = (self.call.as_mut(), self.held_call.as_ref()) else {70
return;71
};72
let model = &call.model;73
let Some(consult) = call74
.consult75
.as_mut()76
.filter(|consult| consult.ready_to_transfer(model))77
else {78
return;79
};80
consult.transfer = ConsultTransfer::Pending;81
let (mri, display_name) = consult.target.clone();82
send_to(83
held,84
CallCommand::Transfer {85
target: Callee { mri, display_name },86
replaces: consult.replacement.clone(),87
},88
);89
cx.notify();90
}91
92
pub fn resume_held_call(&mut self, _cx: &mut Context<Self>) {93
let (Some(call), Some(held)) = (self.call.as_ref(), self.held_call.as_ref()) else {94
return;95
};96
if call.consult.is_none() {97
return;98
}99
send_to(held, CallCommand::Hold(false));100
send_to(call, CallCommand::Hangup);101
}102
103
pub(super) fn is_held_call(&self, call_id: u64) -> bool {104
self.held_call.as_ref().is_some_and(|held| held.id == call_id)105
}106
107
pub(super) fn apply_held_call_update(&mut self, update: CallUpdate, cx: &mut Context<Self>) {108
let Some(held) = self.held_call.as_mut() else {109
return;110
};111
match update {112
CallUpdate::Notice(text) => {113
self.raise_notice(text, None, cx);114
return;115
}116
CallUpdate::TransferResult { succeeded } => {117
self.settle_consult_transfer(succeeded);118
cx.notify();119
return;120
}121
CallUpdate::VideoReady122
| CallUpdate::Levels { .. }123
| CallUpdate::Stats { .. }124
| CallUpdate::Sample(_)125
| CallUpdate::Health(_) => return,126
other => held.model.apply(other),127
}128
if held.model.ended_reason().is_none() {129
return;130
}131
let Some(mut ended) = self.held_call.take() else {132
return;133
};134
ended.pictures.clear(cx);135
let consult = self.call.as_mut().and_then(|call| {136
let transferred = call137
.consult138
.as_ref()139
.is_some_and(|consult| consult.transfer == ConsultTransfer::Done);140
if transferred { None } else { call.consult.take() }141
});142
if let Some(consult) = consult {143
self.raise_notice(format!("{} hung up", consult.held_name), None, cx);144
}145
self.refresh_call_history_after_call(cx);146
cx.emit(AppEvent::Call);147
cx.notify();148
}149
150
fn settle_consult_transfer(&mut self, succeeded: bool) {151
let Some(call) = self.call.as_mut() else {152
return;153
};154
let Some(consult) = call.consult.as_mut() else {155
return;156
};157
consult.transfer = if succeeded {158
ConsultTransfer::Done159
} else {160
ConsultTransfer::Idle161
};162
if succeeded {163
send_to(call, CallCommand::Hangup);164
}165
}166
}167
168
#[cfg(test)]169
mod tests {170
use std::sync::Arc;171
use std::time::Instant;172
173
use calling::{174
CallCommand, CallControl, CallState, CallUpdate, Callee, EndReason, HoldState, Replacement,175
call_channel,176
};177
use gpui_kit::{AppContext as _, Entity, TestAppContext};178
use store::Store;179
180
use super::{ActiveCall, CallModel, ConsultCall, TransferCandidate};181
use crate::app_state::{AppState, Mode};182
183
const HELD_ID: u64 = 7;184
const CONSULT_ID: u64 = 8;185
186
fn connected(name: &str, mri: &str) -> CallModel {187
let mut model = CallModel::people(name, &[(mri.into(), name.into())]);188
model.apply(CallUpdate::State(CallState::Connected {189
since: Instant::now(),190
}));191
model192
}193
194
fn consulting(cx: &mut TestAppContext) -> (Entity<AppState>, CallControl, CallControl) {195
cx.update(gpui_kit::init);196
let store = Arc::new(Store::open_in_memory().unwrap());197
let app = cx.update(|cx| cx.new(|_| AppState::new(store, Mode::default())));198
let (held_handle, held_control) = call_channel();199
let (consult_handle, consult_control) = call_channel();200
cx.update(|cx| {201
app.update(cx, |state, _| {202
let mut held_model = connected("Chris", "8:orgid:chris");203
held_model.apply(CallUpdate::Hold(HoldState::Local));204
state.held_call = Some(ActiveCall::new(205
HELD_ID,206
held_model,207
held_handle.commands,208
None,209
held_handle.video,210
));211
let mut consult = ActiveCall::new(212
CONSULT_ID,213
connected("Ana", "8:orgid:ana"),214
consult_handle.commands,215
None,216
consult_handle.video,217
);218
consult.consult = Some(ConsultCall::new(219
("8:orgid:ana".into(), "Ana".into()),220
"Chris".into(),221
));222
state.call = Some(consult);223
})224
});225
(app, held_control, consult_control)226
}227
228
fn ended() -> CallUpdate {229
CallUpdate::State(CallState::Ended {230
reason: EndReason::LocalHangup,231
})232
}233
234
fn leg() -> Replacement {235
Replacement {236
link: "https://cc/ana/replacement".into(),237
participant_id: Some("leg-ana".into()),238
}239
}240
241
#[gpui_kit::test]242
fn consulting_holds_the_first_call_and_shows_the_consult_call(cx: &mut TestAppContext) {243
cx.update(gpui_kit::init);244
let store = Arc::new(Store::open_in_memory().unwrap());245
let app = cx.update(|cx| cx.new(|_| AppState::new(store, Mode::default())));246
let (held_handle, mut held_control) = call_channel();247
let (consult_handle, _consult_control) = call_channel();248
let target = TransferCandidate {249
mri: "8:orgid:ana".into(),250
name: "Ana".into(),251
user_id: Some("ana".into()),252
chat_id: "19:ana".into(),253
};254
cx.update(|cx| {255
app.update(cx, |state, cx| {256
state.call = Some(ActiveCall::new(257
HELD_ID,258
connected("Chris", "8:orgid:chris"),259
held_handle.commands,260
None,261
held_handle.video,262
));263
state.begin_consult(target, consult_handle, cx);264
assert_eq!(state.held_call.as_ref().unwrap().id, HELD_ID);265
let call = state.call.as_ref().unwrap();266
assert_ne!(call.id, HELD_ID);267
assert_eq!(call.model.peer_name, "Ana");268
assert_eq!(call.consult.as_ref().unwrap().banner_text(), "Chris is on hold");269
})270
});271
assert_eq!(held_control.try_recv_command(), Some(CallCommand::Hold(true)));272
}273
274
#[gpui_kit::test]275
fn the_transfer_goes_to_the_held_call_with_the_consulted_persons_leg(cx: &mut TestAppContext) {276
let (app, mut held_control, mut consult_control) = consulting(cx);277
cx.update(|cx| {278
app.update(cx, |state, cx| {279
state.transfer_consulted(cx);280
state.apply_call_update(CONSULT_ID, CallUpdate::ReplacementLink(leg()), cx);281
state.transfer_consulted(cx);282
state.transfer_consulted(cx);283
})284
});285
assert_eq!(286
held_control.try_recv_command(),287
Some(CallCommand::Transfer {288
target: Callee {289
mri: "8:orgid:ana".into(),290
display_name: "Ana".into()291
},292
replaces: Some(leg()),293
})294
);295
assert_eq!(held_control.try_recv_command(), None);296
assert_eq!(consult_control.try_recv_command(), None);297
}298
299
#[gpui_kit::test]300
fn a_failed_transfer_can_be_tried_again_and_a_completed_one_ends_both_calls(301
cx: &mut TestAppContext,302
) {303
let (app, mut held_control, mut consult_control) = consulting(cx);304
cx.update(|cx| {305
app.update(cx, |state, cx| {306
state.apply_call_update(CONSULT_ID, CallUpdate::ReplacementLink(leg()), cx);307
state.transfer_consulted(cx);308
state.apply_call_update(HELD_ID, CallUpdate::TransferResult { succeeded: false }, cx);309
state.transfer_consulted(cx);310
state.apply_call_update(HELD_ID, CallUpdate::TransferResult { succeeded: true }, cx);311
state.apply_call_update(HELD_ID, ended(), cx);312
assert!(state.held_call.is_none());313
assert!(state.call.as_ref().unwrap().consult.is_some());314
state.apply_call_update(CONSULT_ID, ended(), cx);315
assert!(state.call.is_none());316
assert_eq!(state.notice.as_ref().unwrap().text, "Call transferred to Ana");317
})318
});319
assert!(matches!(held_control.try_recv_command(), Some(CallCommand::Transfer { .. })));320
assert!(matches!(held_control.try_recv_command(), Some(CallCommand::Transfer { .. })));321
assert_eq!(consult_control.try_recv_command(), Some(CallCommand::Hangup));322
}323
324
#[gpui_kit::test]325
fn the_consult_call_keeps_going_when_the_held_caller_hangs_up(cx: &mut TestAppContext) {326
let (app, _held_control, mut consult_control) = consulting(cx);327
cx.update(|cx| {328
app.update(cx, |state, cx| {329
state.apply_call_update(HELD_ID, ended(), cx);330
assert!(state.held_call.is_none());331
let call = state.call.as_ref().expect("consult call stays");332
assert_eq!(call.id, CONSULT_ID);333
assert!(call.consult.is_none());334
assert!(call.model.is_active());335
assert_eq!(state.notice.as_ref().unwrap().text, "Chris hung up");336
})337
});338
assert_eq!(consult_control.try_recv_command(), None);339
}340
341
#[gpui_kit::test]342
fn the_held_call_comes_back_when_the_consult_ends_and_resume_ends_the_consult(343
cx: &mut TestAppContext,344
) {345
let (app, mut held_control, mut consult_control) = consulting(cx);346
cx.update(|cx| {347
app.update(cx, |state, cx| {348
state.resume_held_call(cx);349
state.apply_call_update(CONSULT_ID, ended(), cx);350
let call = state.call.as_ref().expect("held call is back");351
assert_eq!(call.id, HELD_ID);352
assert!(state.held_call.is_none());353
assert_eq!(state.notice.as_ref().unwrap().text, "The consultation ended");354
})355
});356
assert_eq!(held_control.try_recv_command(), Some(CallCommand::Hold(false)));357
assert_eq!(consult_control.try_recv_command(), Some(CallCommand::Hangup));358
}359
360
#[gpui_kit::test]361
fn held_call_updates_never_reach_the_visible_consult_call(cx: &mut TestAppContext) {362
let (app, _held_control, _consult_control) = consulting(cx);363
cx.update(|cx| {364
app.update(cx, |state, cx| {365
state.apply_call_update(HELD_ID, CallUpdate::Hold(HoldState::Active), cx);366
assert_eq!(state.held_call.as_ref().unwrap().model.hold, HoldState::Active);367
assert_eq!(state.call.as_ref().unwrap().model.hold, HoldState::Active);368
assert_eq!(state.call.as_ref().unwrap().model.peer_name, "Ana");369
assert!(!state.can_transfer_call());370
})371
});372
}373
}@@ -8,7 +8,7 @@ use calling::{
8
8
CallState, CallUpdate, Caller, CaptionEntry, CaptionState, ContentShare, DeviceChoice,
9
9
DeviceLists, EndReason, HealthSample, HoldState, IncomingRing, Limitation, MediaPath,
10
10
MeetingCapability, MeetingOptions, MeetingRole, MeetingTarget, Modality, NetworkLevel, Progress,
11
PublishedState, RaisedHand, Reaction, RecordingKind, RosterEntry, ShareKind, ShareSource, StopScope,
11
PublishedState, RaisedHand, Reaction, RecordingKind, Replacement, RosterEntry, ShareKind, ShareSource, StopScope,
12
12
TransportDetails, VideoKey, call_channel,
13
13
};
14
14
use calling::call::VideoReport;
@@ -94,6 +94,7 @@ pub enum DemoScene {
94
94
Consent,
95
95
Hold,
96
96
Held,
97
Consult,
97
98
Breakout,
98
99
Whiteboard,
99
100
Network,
@@ -109,6 +110,7 @@ impl DemoScene {
109
110
"consent" => DemoScene::Consent,
110
111
"hold" => DemoScene::Hold,
111
112
"held" => DemoScene::Held,
113
"consult" => DemoScene::Consult,
112
114
"breakout" => DemoScene::Breakout,
113
115
"whiteboard" => DemoScene::Whiteboard,
114
116
"network" => DemoScene::Network,
@@ -119,7 +121,10 @@ impl DemoScene {
119
121
}
120
122
121
123
pub fn is_one_to_one(self) -> bool {
122
matches!(self, DemoScene::Call | DemoScene::Hold | DemoScene::Held | DemoScene::Network)
124
matches!(
125
self,
126
DemoScene::Call | DemoScene::Hold | DemoScene::Held | DemoScene::Consult | DemoScene::Network
127
)
123
128
}
124
129
125
130
pub fn guests(self) -> Option<usize> {
@@ -313,9 +318,9 @@ async fn run_demo_call(mut control: CallControl, script: DemoCall, scene: DemoSc
313
318
roster.push(RosterEntry { mri: calling::captions::RECORDING_BOT_MRI.to_owned(), ..RosterEntry::default() });
314
319
}
315
320
if matches!(script, DemoCall::People(_)) {
316
control.send(CallUpdate::ReplacementLink(
317
DEMO_REPLACEMENT_LINK.to_owned(),
318
));
321
control.send(CallUpdate::ReplacementLink(Replacement::of_call(
322
DEMO_REPLACEMENT_LINK,
323
)));
319
324
}
320
325
if matches!(
321
326
script,
@@ -413,6 +418,7 @@ fn start_scene(control: &CallControl, scene: DemoScene) {
413
418
DemoScene::Held => control.send(CallUpdate::Hold(HoldState::Remote)),
414
419
DemoScene::Network => control.send(CallUpdate::Health(poor_network_health())),
415
420
DemoScene::Call
421
| DemoScene::Consult
416
422
| DemoScene::Breakout
417
423
| DemoScene::Whiteboard
418
424
| DemoScene::Gallery
@@ -677,6 +683,7 @@ async fn speak_until_hangup(
677
683
Some(CallCommand::ConsentToRecording) => control.send(CallUpdate::ConsentRequired(false)),
678
684
Some(CallCommand::Hold(hold)) => control.send(CallUpdate::Hold(if hold { HoldState::Local } else { HoldState::Active })),
679
685
Some(CallCommand::Transfer { .. }) => {
686
control.send(CallUpdate::TransferResult { succeeded: true });
680
687
control.send(CallUpdate::Notice("Call transferred".to_owned()));
681
688
end(&control, EndReason::LocalHangup);
682
689
return;
@@ -8,7 +8,7 @@ use calling::{8
CallState, CallUpdate, Caller, CaptionEntry, CaptionState, ContentShare, DeviceChoice,8
CallState, CallUpdate, Caller, CaptionEntry, CaptionState, ContentShare, DeviceChoice,9
DeviceLists, EndReason, HealthSample, HoldState, IncomingRing, Limitation, MediaPath,9
DeviceLists, EndReason, HealthSample, HoldState, IncomingRing, Limitation, MediaPath,10
MeetingCapability, MeetingOptions, MeetingRole, MeetingTarget, Modality, NetworkLevel, Progress,10
MeetingCapability, MeetingOptions, MeetingRole, MeetingTarget, Modality, NetworkLevel, Progress,11
PublishedState, RaisedHand, Reaction, RecordingKind, RosterEntry, ShareKind, ShareSource, StopScope,11
PublishedState, RaisedHand, Reaction, RecordingKind, Replacement, RosterEntry, ShareKind, ShareSource, StopScope,12
TransportDetails, VideoKey, call_channel,12
TransportDetails, VideoKey, call_channel,13
};13
};14
use calling::call::VideoReport;14
use calling::call::VideoReport;@@ -94,6 +94,7 @@ pub enum DemoScene {94
Consent,94
Consent,95
Hold,95
Hold,96
Held,96
Held,97
Consult,97
Breakout,98
Breakout,98
Whiteboard,99
Whiteboard,99
Network,100
Network,@@ -109,6 +110,7 @@ impl DemoScene {109
"consent" => DemoScene::Consent,110
"consent" => DemoScene::Consent,110
"hold" => DemoScene::Hold,111
"hold" => DemoScene::Hold,111
"held" => DemoScene::Held,112
"held" => DemoScene::Held,113
"consult" => DemoScene::Consult,112
"breakout" => DemoScene::Breakout,114
"breakout" => DemoScene::Breakout,113
"whiteboard" => DemoScene::Whiteboard,115
"whiteboard" => DemoScene::Whiteboard,114
"network" => DemoScene::Network,116
"network" => DemoScene::Network,@@ -119,7 +121,10 @@ impl DemoScene {119
}121
}120
122
121
pub fn is_one_to_one(self) -> bool {123
pub fn is_one_to_one(self) -> bool {122
matches!(self, DemoScene::Call | DemoScene::Hold | DemoScene::Held | DemoScene::Network)124
matches!(125
self,126
DemoScene::Call | DemoScene::Hold | DemoScene::Held | DemoScene::Consult | DemoScene::Network127
)123
}128
}124
129
125
pub fn guests(self) -> Option<usize> {130
pub fn guests(self) -> Option<usize> {@@ -313,9 +318,9 @@ async fn run_demo_call(mut control: CallControl, script: DemoCall, scene: DemoSc313
roster.push(RosterEntry { mri: calling::captions::RECORDING_BOT_MRI.to_owned(), ..RosterEntry::default() });318
roster.push(RosterEntry { mri: calling::captions::RECORDING_BOT_MRI.to_owned(), ..RosterEntry::default() });314
}319
}315
if matches!(script, DemoCall::People(_)) {320
if matches!(script, DemoCall::People(_)) {316
control.send(CallUpdate::ReplacementLink(321
control.send(CallUpdate::ReplacementLink(Replacement::of_call(317
DEMO_REPLACEMENT_LINK.to_owned(),322
DEMO_REPLACEMENT_LINK,318
));323
)));319
}324
}320
if matches!(325
if matches!(321
script,326
script,@@ -413,6 +418,7 @@ fn start_scene(control: &CallControl, scene: DemoScene) {413
DemoScene::Held => control.send(CallUpdate::Hold(HoldState::Remote)),418
DemoScene::Held => control.send(CallUpdate::Hold(HoldState::Remote)),414
DemoScene::Network => control.send(CallUpdate::Health(poor_network_health())),419
DemoScene::Network => control.send(CallUpdate::Health(poor_network_health())),415
DemoScene::Call420
DemoScene::Call421
| DemoScene::Consult416
| DemoScene::Breakout422
| DemoScene::Breakout417
| DemoScene::Whiteboard423
| DemoScene::Whiteboard418
| DemoScene::Gallery424
| DemoScene::Gallery@@ -677,6 +683,7 @@ async fn speak_until_hangup(677
Some(CallCommand::ConsentToRecording) => control.send(CallUpdate::ConsentRequired(false)),683
Some(CallCommand::ConsentToRecording) => control.send(CallUpdate::ConsentRequired(false)),678
Some(CallCommand::Hold(hold)) => control.send(CallUpdate::Hold(if hold { HoldState::Local } else { HoldState::Active })),684
Some(CallCommand::Hold(hold)) => control.send(CallUpdate::Hold(if hold { HoldState::Local } else { HoldState::Active })),679
Some(CallCommand::Transfer { .. }) => {685
Some(CallCommand::Transfer { .. }) => {686
control.send(CallUpdate::TransferResult { succeeded: true });680
control.send(CallUpdate::Notice("Call transferred".to_owned()));687
control.send(CallUpdate::Notice("Call transferred".to_owned()));681
end(&control, EndReason::LocalHangup);688
end(&control, EndReason::LocalHangup);682
return;689
return;@@ -1,12 +1,12 @@
1
1
use calling::{
2
CallCommand, CallHandle, CallSpec, CallState, Callee, EndKind, EndReason, HoldState,
2
CallCommand, CallSpec, Callee, EndKind, EndReason, HoldState,
3
3
};
4
4
use gpui_kit::*;
5
5
6
6
use super::background::BackgroundPick;
7
use super::demo::{DemoCall, start_demo_call};
7
use super::demo::DemoCall;
8
8
use super::health::HealthBanner;
9
use super::model::{ActiveCall, BreakoutState, CallKind, CallModel, ConsultCall, PendingMove};
9
use super::model::{ActiveCall, BreakoutState, CallKind, CallModel, PendingMove};
10
10
use super::recording_menu::RecordAction;
11
11
use super::target::plan_for_chat;
12
12
use crate::app_state::{AppEvent, AppState};
@@ -206,6 +206,7 @@ impl AppState {
206
206
self.call
207
207
.as_ref()
208
208
.is_some_and(|call| call.model.can_transfer() && call.consult.is_none())
209
&& self.held_call.is_none()
209
210
}
210
211
211
212
pub fn open_transfer_picker(
@@ -240,142 +241,6 @@ impl AppState {
240
241
});
241
242
}
242
243
243
pub fn start_consult(&mut self, target: TransferCandidate, cx: &mut Context<Self>) {
244
self.close_transfer_picker(cx);
245
if !self.can_transfer_call() {
246
return;
247
}
248
let spec = CallSpec::People {
249
callees: vec![Callee {
250
mri: target.mri.clone(),
251
display_name: target.name.clone(),
252
}],
253
thread_id: target.chat_id.clone(),
254
};
255
let handle = if self.mode.demo {
256
Some(start_demo_call(DemoCall::People(vec![(
257
target.mri.clone(),
258
target.name.clone(),
259
)])))
260
} else {
261
self.call_launcher
262
.clone()
263
.map(|launcher| launcher.start_consult(spec))
264
};
265
let Some(CallHandle {
266
commands, updates, ..
267
}) = handle
268
else {
269
self.raise_notice("Not connected to Teams yet".to_owned(), None, cx);
270
return;
271
};
272
self.note_call_feature("consult", format!("start with {}", target.mri));
273
self.send_call_command(CallCommand::Hold(true));
274
self.call_count += 1;
275
let consult_id = self.call_count;
276
let Some(call) = self.call.as_mut() else {
277
return;
278
};
279
let call_id = call.id;
280
call.consult = Some(ConsultCall {
281
id: consult_id,
282
target: (target.mri, target.name),
283
commands,
284
state: CallState::Connecting,
285
replacement: None,
286
transferring: false,
287
});
288
self.follow_consult(call_id, consult_id, updates, cx);
289
cx.notify();
290
}
291
292
fn follow_consult(
293
&mut self,
294
call_id: u64,
295
consult_id: u64,
296
mut updates: tokio::sync::mpsc::UnboundedReceiver<calling::CallUpdate>,
297
cx: &mut Context<Self>,
298
) {
299
cx.spawn(async move |this, cx| {
300
while let Some(update) = updates.recv().await {
301
if this
302
.update(cx, |state, cx| {
303
state.apply_consult_update(call_id, consult_id, update, cx)
304
})
305
.is_err()
306
{
307
return;
308
}
309
}
310
})
311
.detach();
312
}
313
314
pub(super) fn apply_consult_update(
315
&mut self,
316
call_id: u64,
317
consult_id: u64,
318
update: calling::CallUpdate,
319
cx: &mut Context<Self>,
320
) {
321
let Some(call) = self.call.as_mut().filter(|call| call.id == call_id) else {
322
return;
323
};
324
let Some(consult) = call
325
.consult
326
.as_mut()
327
.filter(|consult| consult.id == consult_id)
328
else {
329
return;
330
};
331
match update {
332
calling::CallUpdate::ReplacementLink(link) => consult.replacement = Some(link),
333
calling::CallUpdate::Notice(text) => self.raise_notice(text, None, cx),
334
calling::CallUpdate::State(state) => {
335
let ended = matches!(state, CallState::Ended { .. });
336
consult.state = state;
337
if ended {
338
let transferring = consult.transferring;
339
call.consult = None;
340
if !transferring {
341
self.note_call_feature("consult", "ended without a transfer".to_owned());
342
self.raise_notice("The consultation ended".to_owned(), None, cx);
343
self.send_call_command(CallCommand::Hold(false));
344
}
345
}
346
}
347
_ => {}
348
}
349
cx.notify();
350
}
351
352
pub fn transfer_consulted(&mut self, _cx: &mut Context<Self>) {
353
let Some(consult) = self
354
.call
355
.as_mut()
356
.and_then(|call| call.consult.as_mut())
357
.filter(|consult| consult.ready_to_transfer())
358
else {
359
return;
360
};
361
consult.transferring = true;
362
let (mri, name) = consult.target.clone();
363
let replaces = consult.replacement.clone();
364
self.send_call_command(CallCommand::Transfer {
365
target: Callee {
366
mri,
367
display_name: name,
368
},
369
replaces,
370
});
371
}
372
373
pub fn cancel_consult(&mut self, _cx: &mut Context<Self>) {
374
if let Some(consult) = self.call.as_ref().and_then(|call| call.consult.as_ref()) {
375
let _ = consult.commands.send(CallCommand::Hangup);
376
}
377
}
378
379
244
pub(super) fn begin_breakout_move(
380
245
&mut self,
381
246
moved: calling::BreakoutMove,
@@ -1,12 +1,12 @@1
use calling::{1
use calling::{2
CallCommand, CallHandle, CallSpec, CallState, Callee, EndKind, EndReason, HoldState,2
CallCommand, CallSpec, Callee, EndKind, EndReason, HoldState,3
};3
};4
use gpui_kit::*;4
use gpui_kit::*;5
5
6
use super::background::BackgroundPick;6
use super::background::BackgroundPick;7
use super::demo::{DemoCall, start_demo_call};7
use super::demo::DemoCall;8
use super::health::HealthBanner;8
use super::health::HealthBanner;9
use super::model::{ActiveCall, BreakoutState, CallKind, CallModel, ConsultCall, PendingMove};9
use super::model::{ActiveCall, BreakoutState, CallKind, CallModel, PendingMove};10
use super::recording_menu::RecordAction;10
use super::recording_menu::RecordAction;11
use super::target::plan_for_chat;11
use super::target::plan_for_chat;12
use crate::app_state::{AppEvent, AppState};12
use crate::app_state::{AppEvent, AppState};@@ -206,6 +206,7 @@ impl AppState {206
self.call206
self.call207
.as_ref()207
.as_ref()208
.is_some_and(|call| call.model.can_transfer() && call.consult.is_none())208
.is_some_and(|call| call.model.can_transfer() && call.consult.is_none())209
&& self.held_call.is_none()209
}210
}210
211
211
pub fn open_transfer_picker(212
pub fn open_transfer_picker(@@ -240,142 +241,6 @@ impl AppState {240
});241
});241
}242
}242
243
243
pub fn start_consult(&mut self, target: TransferCandidate, cx: &mut Context<Self>) {244
self.close_transfer_picker(cx);245
if !self.can_transfer_call() {246
return;247
}248
let spec = CallSpec::People {249
callees: vec![Callee {250
mri: target.mri.clone(),251
display_name: target.name.clone(),252
}],253
thread_id: target.chat_id.clone(),254
};255
let handle = if self.mode.demo {256
Some(start_demo_call(DemoCall::People(vec![(257
target.mri.clone(),258
target.name.clone(),259
)])))260
} else {261
self.call_launcher262
.clone()263
.map(|launcher| launcher.start_consult(spec))264
};265
let Some(CallHandle {266
commands, updates, ..267
}) = handle268
else {269
self.raise_notice("Not connected to Teams yet".to_owned(), None, cx);270
return;271
};272
self.note_call_feature("consult", format!("start with {}", target.mri));273
self.send_call_command(CallCommand::Hold(true));274
self.call_count += 1;275
let consult_id = self.call_count;276
let Some(call) = self.call.as_mut() else {277
return;278
};279
let call_id = call.id;280
call.consult = Some(ConsultCall {281
id: consult_id,282
target: (target.mri, target.name),283
commands,284
state: CallState::Connecting,285
replacement: None,286
transferring: false,287
});288
self.follow_consult(call_id, consult_id, updates, cx);289
cx.notify();290
}291
292
fn follow_consult(293
&mut self,294
call_id: u64,295
consult_id: u64,296
mut updates: tokio::sync::mpsc::UnboundedReceiver<calling::CallUpdate>,297
cx: &mut Context<Self>,298
) {299
cx.spawn(async move |this, cx| {300
while let Some(update) = updates.recv().await {301
if this302
.update(cx, |state, cx| {303
state.apply_consult_update(call_id, consult_id, update, cx)304
})305
.is_err()306
{307
return;308
}309
}310
})311
.detach();312
}313
314
pub(super) fn apply_consult_update(315
&mut self,316
call_id: u64,317
consult_id: u64,318
update: calling::CallUpdate,319
cx: &mut Context<Self>,320
) {321
let Some(call) = self.call.as_mut().filter(|call| call.id == call_id) else {322
return;323
};324
let Some(consult) = call325
.consult326
.as_mut()327
.filter(|consult| consult.id == consult_id)328
else {329
return;330
};331
match update {332
calling::CallUpdate::ReplacementLink(link) => consult.replacement = Some(link),333
calling::CallUpdate::Notice(text) => self.raise_notice(text, None, cx),334
calling::CallUpdate::State(state) => {335
let ended = matches!(state, CallState::Ended { .. });336
consult.state = state;337
if ended {338
let transferring = consult.transferring;339
call.consult = None;340
if !transferring {341
self.note_call_feature("consult", "ended without a transfer".to_owned());342
self.raise_notice("The consultation ended".to_owned(), None, cx);343
self.send_call_command(CallCommand::Hold(false));344
}345
}346
}347
_ => {}348
}349
cx.notify();350
}351
352
pub fn transfer_consulted(&mut self, _cx: &mut Context<Self>) {353
let Some(consult) = self354
.call355
.as_mut()356
.and_then(|call| call.consult.as_mut())357
.filter(|consult| consult.ready_to_transfer())358
else {359
return;360
};361
consult.transferring = true;362
let (mri, name) = consult.target.clone();363
let replaces = consult.replacement.clone();364
self.send_call_command(CallCommand::Transfer {365
target: Callee {366
mri,367
display_name: name,368
},369
replaces,370
});371
}372
373
pub fn cancel_consult(&mut self, _cx: &mut Context<Self>) {374
if let Some(consult) = self.call.as_ref().and_then(|call| call.consult.as_ref()) {375
let _ = consult.commands.send(CallCommand::Hangup);376
}377
}378
379
pub(super) fn begin_breakout_move(244
pub(super) fn begin_breakout_move(380
&mut self,245
&mut self,381
moved: calling::BreakoutMove,246
moved: calling::BreakoutMove,@@ -4,6 +4,7 @@ mod background;
4
4
mod bubbles;
5
5
mod calendar;
6
6
mod caption_style;
7
mod consult;
7
8
mod demo;
8
9
mod demo_scene;
9
10
mod features;
@@ -61,6 +62,8 @@ pub use model::{
61
62
ActiveCall, CAPTION_SHOWN, CallKind, CallModel, Focus, REACTION_SHOWN, Tile, TileSize,
62
63
TileState,
63
64
};
65
#[cfg(test)]
66
pub use model::ConsultCall;
64
67
pub use options_dialog::OptionsDialog;
65
68
pub use overlay::CallWindows;
66
69
pub use prejoin::{AudioChoice, JoinOptions, PendingJoin, load_join_options};
@@ -4,6 +4,7 @@ mod background;4
mod bubbles;4
mod bubbles;5
mod calendar;5
mod calendar;6
mod caption_style;6
mod caption_style;7
mod consult;7
mod demo;8
mod demo;8
mod demo_scene;9
mod demo_scene;9
mod features;10
mod features;@@ -61,6 +62,8 @@ pub use model::{61
ActiveCall, CAPTION_SHOWN, CallKind, CallModel, Focus, REACTION_SHOWN, Tile, TileSize,62
ActiveCall, CAPTION_SHOWN, CallKind, CallModel, Focus, REACTION_SHOWN, Tile, TileSize,62
TileState,63
TileState,63
};64
};65
#[cfg(test)]66
pub use model::ConsultCall;64
pub use options_dialog::OptionsDialog;67
pub use options_dialog::OptionsDialog;65
pub use overlay::CallWindows;68
pub use overlay::CallWindows;66
pub use prejoin::{AudioChoice, JoinOptions, PendingJoin, load_join_options};69
pub use prejoin::{AudioChoice, JoinOptions, PendingJoin, load_join_options};@@ -6,7 +6,7 @@ use std::time::{Duration, Instant};
6
6
use calling::{
7
7
AttendeeLimits, CallCommand, CallState, CallUpdate, CameraDevice, CaptionEntry, CaptionState, ContentShare,
8
8
DeviceChoice, DeviceLists, EndKind, EndReason, HoldState, MeetingCapability, MeetingRole,
9
MeetingTarget, Progress, Reaction, RosterEntry, ShareKind, ShareSource, SpeakingDetector, VideoHub,
9
MeetingTarget, Progress, Reaction, Replacement, RosterEntry, ShareKind, ShareSource, SpeakingDetector, VideoHub,
10
10
VideoWant,
11
11
};
12
12
use tokio::sync::mpsc::UnboundedSender;
@@ -72,28 +72,40 @@ pub struct PendingMove {
72
72
}
73
73
74
74
pub struct ConsultCall {
75
pub id: u64,
76
75
pub target: (String, String),
77
pub commands: UnboundedSender<CallCommand>,
78
pub state: CallState,
79
pub replacement: Option<String>,
80
pub transferring: bool,
76
pub held_name: String,
77
pub replacement: Option<Replacement>,
78
pub transfer: ConsultTransfer,
79
}
80
81
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
82
pub enum ConsultTransfer {
83
#[default]
84
Idle,
85
Pending,
86
Done,
81
87
}
82
88
83
89
impl ConsultCall {
84
pub fn connected(&self) -> bool {
85
matches!(self.state, CallState::Connected { .. })
90
pub fn new(target: (String, String), held_name: String) -> Self {
91
ConsultCall {
92
target,
93
held_name,
94
replacement: None,
95
transfer: ConsultTransfer::Idle,
96
}
86
97
}
87
98
88
pub fn ready_to_transfer(&self) -> bool {
89
self.connected() && self.replacement.is_some()
99
pub fn ready_to_transfer(&self, model: &CallModel) -> bool {
100
model.is_live() && self.replacement.is_some() && self.transfer == ConsultTransfer::Idle
90
101
}
91
102
92
pub fn status_text(&self) -> String {
93
let name = &self.target.1;
94
match &self.state {
95
CallState::Connected { .. } => format!("Consulting {name}"),
96
_ => format!("Calling {name}..."),
103
pub fn banner_text(&self) -> String {
104
match self.transfer {
105
ConsultTransfer::Idle => format!("{} is on hold", self.held_name),
106
ConsultTransfer::Pending | ConsultTransfer::Done => {
107
format!("Transferring {} to {}...", self.held_name, self.target.1)
108
}
97
109
}
98
110
}
99
111
}
@@ -504,7 +516,8 @@ impl CallModel {
504
516
| CallUpdate::MeetingOptionsSaved(_)
505
517
| CallUpdate::WhiteboardUrl(_)
506
518
| CallUpdate::BreakoutMove(_)
507
| CallUpdate::ReplacementLink(_) => {}
519
| CallUpdate::ReplacementLink(_)
520
| CallUpdate::TransferResult { .. } => {}
508
521
}
509
522
}
510
523
@@ -2183,23 +2196,17 @@ mod tests {
2183
2196
2184
2197
#[test]
2185
2198
fn a_consultation_can_transfer_once_connected_with_a_replacement_link() {
2186
let (handle, _control) = calling::call_channel();
2187
let mut consult = ConsultCall {
2188
id: 3,
2189
target: ("8:orgid:ana".into(), "Ana".into()),
2190
commands: handle.commands,
2191
state: CallState::Connecting,
2192
replacement: None,
2193
transferring: false,
2194
};
2195
assert_eq!(consult.status_text(), "Calling Ana...");
2196
assert!(!consult.ready_to_transfer());
2197
consult.state = CallState::Connected {
2199
let mut model = CallModel::people("Ana", &[("8:orgid:ana".into(), "Ana".into())]);
2200
let mut consult = ConsultCall::new(("8:orgid:ana".into(), "Ana".into()), "Chris".into());
2201
assert_eq!(consult.banner_text(), "Chris is on hold");
2202
consult.replacement = Some(Replacement::of_call("https://cc/replacement"));
2203
assert!(!consult.ready_to_transfer(&model));
2204
model.apply(CallUpdate::State(CallState::Connected {
2198
2205
since: Instant::now(),
2199
};
2200
assert_eq!(consult.status_text(), "Consulting Ana");
2201
assert!(!consult.ready_to_transfer());
2202
consult.replacement = Some("https://cc/replacement".into());
2203
assert!(consult.ready_to_transfer());
2206
}));
2207
assert!(consult.ready_to_transfer(&model));
2208
consult.transfer = ConsultTransfer::Pending;
2209
assert!(!consult.ready_to_transfer(&model));
2210
assert_eq!(consult.banner_text(), "Transferring Chris to Ana...");
2204
2211
}
2205
2212
}
@@ -6,7 +6,7 @@ use std::time::{Duration, Instant};6
use calling::{6
use calling::{7
AttendeeLimits, CallCommand, CallState, CallUpdate, CameraDevice, CaptionEntry, CaptionState, ContentShare,7
AttendeeLimits, CallCommand, CallState, CallUpdate, CameraDevice, CaptionEntry, CaptionState, ContentShare,8
DeviceChoice, DeviceLists, EndKind, EndReason, HoldState, MeetingCapability, MeetingRole,8
DeviceChoice, DeviceLists, EndKind, EndReason, HoldState, MeetingCapability, MeetingRole,9
MeetingTarget, Progress, Reaction, RosterEntry, ShareKind, ShareSource, SpeakingDetector, VideoHub,9
MeetingTarget, Progress, Reaction, Replacement, RosterEntry, ShareKind, ShareSource, SpeakingDetector, VideoHub,10
VideoWant,10
VideoWant,11
};11
};12
use tokio::sync::mpsc::UnboundedSender;12
use tokio::sync::mpsc::UnboundedSender;@@ -72,28 +72,40 @@ pub struct PendingMove {72
}72
}73
73
74
pub struct ConsultCall {74
pub struct ConsultCall {75
pub id: u64,76
pub target: (String, String),75
pub target: (String, String),77
pub commands: UnboundedSender<CallCommand>,76
pub held_name: String,78
pub state: CallState,77
pub replacement: Option<Replacement>,79
pub replacement: Option<String>,78
pub transfer: ConsultTransfer,80
pub transferring: bool,79
}80
81
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]82
pub enum ConsultTransfer {83
#[default]84
Idle,85
Pending,86
Done,81
}87
}82
88
83
impl ConsultCall {89
impl ConsultCall {84
pub fn connected(&self) -> bool {90
pub fn new(target: (String, String), held_name: String) -> Self {85
matches!(self.state, CallState::Connected { .. })91
ConsultCall {92
target,93
held_name,94
replacement: None,95
transfer: ConsultTransfer::Idle,96
}86
}97
}87
98
88
pub fn ready_to_transfer(&self) -> bool {99
pub fn ready_to_transfer(&self, model: &CallModel) -> bool {89
self.connected() && self.replacement.is_some()100
model.is_live() && self.replacement.is_some() && self.transfer == ConsultTransfer::Idle90
}101
}91
102
92
pub fn status_text(&self) -> String {103
pub fn banner_text(&self) -> String {93
let name = &self.target.1;104
match self.transfer {94
match &self.state {105
ConsultTransfer::Idle => format!("{} is on hold", self.held_name),95
CallState::Connected { .. } => format!("Consulting {name}"),106
ConsultTransfer::Pending | ConsultTransfer::Done => {96
_ => format!("Calling {name}..."),107
format!("Transferring {} to {}...", self.held_name, self.target.1)108
}97
}109
}98
}110
}99
}111
}@@ -504,7 +516,8 @@ impl CallModel {504
| CallUpdate::MeetingOptionsSaved(_)516
| CallUpdate::MeetingOptionsSaved(_)505
| CallUpdate::WhiteboardUrl(_)517
| CallUpdate::WhiteboardUrl(_)506
| CallUpdate::BreakoutMove(_)518
| CallUpdate::BreakoutMove(_)507
| CallUpdate::ReplacementLink(_) => {}519
| CallUpdate::ReplacementLink(_)520
| CallUpdate::TransferResult { .. } => {}508
}521
}509
}522
}510
523
@@ -2183,23 +2196,17 @@ mod tests {2183
2196
2184
#[test]2197
#[test]2185
fn a_consultation_can_transfer_once_connected_with_a_replacement_link() {2198
fn a_consultation_can_transfer_once_connected_with_a_replacement_link() {2186
let (handle, _control) = calling::call_channel();2199
let mut model = CallModel::people("Ana", &[("8:orgid:ana".into(), "Ana".into())]);2187
let mut consult = ConsultCall {2200
let mut consult = ConsultCall::new(("8:orgid:ana".into(), "Ana".into()), "Chris".into());2188
id: 3,2201
assert_eq!(consult.banner_text(), "Chris is on hold");2189
target: ("8:orgid:ana".into(), "Ana".into()),2202
consult.replacement = Some(Replacement::of_call("https://cc/replacement"));2190
commands: handle.commands,2203
assert!(!consult.ready_to_transfer(&model));2191
state: CallState::Connecting,2204
model.apply(CallUpdate::State(CallState::Connected {2192
replacement: None,2193
transferring: false,2194
};2195
assert_eq!(consult.status_text(), "Calling Ana...");2196
assert!(!consult.ready_to_transfer());2197
consult.state = CallState::Connected {2198
since: Instant::now(),2205
since: Instant::now(),2199
};2206
}));2200
assert_eq!(consult.status_text(), "Consulting Ana");2207
assert!(consult.ready_to_transfer(&model));2201
assert!(!consult.ready_to_transfer());2208
consult.transfer = ConsultTransfer::Pending;2202
consult.replacement = Some("https://cc/replacement".into());2209
assert!(!consult.ready_to_transfer(&model));2203
assert!(consult.ready_to_transfer());2210
assert_eq!(consult.banner_text(), "Transferring Chris to Ana...");2204
}2211
}2205
}2212
}@@ -345,14 +345,14 @@ impl CallRecorder {
345
345
let mut records: Vec<FeatureRecord> = self.features.clone();
346
346
for entry in timeline {
347
347
if entry.label == TRANSFER_LABEL
348
&& let Some(record) = records.iter_mut().rev().find(|record| record.feature == "transfer" && record.outcome == Outcome::Requested)
348
&& let Some(record) = oldest_pending(&mut records, TRANSFER_LABEL)
349
349
{
350
350
record.outcome = Outcome::Confirmed(entry.elapsed_ms);
351
351
}
352
352
let Some((_, feature)) = FEATURE_FAILURE_LABELS.iter().find(|(label, _)| entry.label == *label) else {
353
353
continue;
354
354
};
355
if let Some(record) = records.iter_mut().rev().find(|record| record.feature == *feature && record.outcome == Outcome::Requested) {
355
if let Some(record) = oldest_pending(&mut records, feature) {
356
356
record.outcome = Outcome::Failed(entry.detail.clone());
357
357
}
358
358
}
@@ -377,6 +377,10 @@ impl CallRecorder {
377
377
}
378
378
}
379
379
380
fn oldest_pending<'a>(records: &'a mut [FeatureRecord], feature: &str) -> Option<&'a mut FeatureRecord> {
381
records.iter_mut().find(|record| record.feature == feature && record.outcome == Outcome::Requested)
382
}
383
380
384
fn placeholders(scrubber: &mut Scrubber, people: &[(String, String)]) -> Vec<String> {
381
385
let mut known = vec![super::scrub::SELF_PLACEHOLDER.to_owned()];
382
386
for (mri, _) in people {
@@ -345,14 +345,14 @@ impl CallRecorder {345
let mut records: Vec<FeatureRecord> = self.features.clone();345
let mut records: Vec<FeatureRecord> = self.features.clone();346
for entry in timeline {346
for entry in timeline {347
if entry.label == TRANSFER_LABEL347
if entry.label == TRANSFER_LABEL348
&& let Some(record) = records.iter_mut().rev().find(|record| record.feature == "transfer" && record.outcome == Outcome::Requested)348
&& let Some(record) = oldest_pending(&mut records, TRANSFER_LABEL)349
{349
{350
record.outcome = Outcome::Confirmed(entry.elapsed_ms);350
record.outcome = Outcome::Confirmed(entry.elapsed_ms);351
}351
}352
let Some((_, feature)) = FEATURE_FAILURE_LABELS.iter().find(|(label, _)| entry.label == *label) else {352
let Some((_, feature)) = FEATURE_FAILURE_LABELS.iter().find(|(label, _)| entry.label == *label) else {353
continue;353
continue;354
};354
};355
if let Some(record) = records.iter_mut().rev().find(|record| record.feature == *feature && record.outcome == Outcome::Requested) {355
if let Some(record) = oldest_pending(&mut records, feature) {356
record.outcome = Outcome::Failed(entry.detail.clone());356
record.outcome = Outcome::Failed(entry.detail.clone());357
}357
}358
}358
}@@ -377,6 +377,10 @@ impl CallRecorder {377
}377
}378
}378
}379
379
380
fn oldest_pending<'a>(records: &'a mut [FeatureRecord], feature: &str) -> Option<&'a mut FeatureRecord> {381
records.iter_mut().find(|record| record.feature == feature && record.outcome == Outcome::Requested)382
}383
380
fn placeholders(scrubber: &mut Scrubber, people: &[(String, String)]) -> Vec<String> {384
fn placeholders(scrubber: &mut Scrubber, people: &[(String, String)]) -> Vec<String> {381
let mut known = vec![super::scrub::SELF_PLACEHOLDER.to_owned()];385
let mut known = vec![super::scrub::SELF_PLACEHOLDER.to_owned()];382
for (mri, _) in people {386
for (mri, _) in people {@@ -384,6 +384,36 @@ mod tests {
384
384
assert!(document.stem.ends_with("-1to1"));
385
385
}
386
386
387
#[test]
388
fn each_transfer_answer_settles_the_transfer_it_belongs_to() {
389
let mut recorder = recorder();
390
let transfer = CallCommand::Transfer {
391
target: Callee { mri: PEER_MRI.to_owned(), display_name: "Mara Lindqvist".to_owned() },
392
replaces: None,
393
};
394
recorder.command(&transfer);
395
recorder.command(&transfer);
396
let entry = |elapsed_ms, label: &str, detail: &str| TimelineEntry { elapsed_ms, label: label.to_owned(), detail: detail.to_owned() };
397
recorder.observe(&CallUpdate::Diagnostics(Box::new(CallDiagnostics {
398
timeline: vec![
399
entry(10, "transfer accepted", "by the target"),
400
entry(20, "transfer failed", "code 487 subCode 0"),
401
entry(30, "transfer accepted", "by the target"),
402
entry(40, "transfer", "completed"),
403
],
404
..CallDiagnostics::default()
405
})));
406
let json: serde_json::Value = serde_json::from_str(&recorder.document().json).expect("valid json");
407
let transfers: Vec<(&str, &serde_json::Value)> = json["features"]
408
.as_array()
409
.unwrap()
410
.iter()
411
.filter(|feature| feature["feature"] == "transfer")
412
.map(|feature| (feature["result"].as_str().unwrap(), &feature["confirmed_at_ms"]))
413
.collect();
414
assert_eq!(transfers, [("failed", &serde_json::Value::Null), ("ok", &serde_json::json!(40))]);
415
}
416
387
417
#[test]
388
418
fn neither_file_holds_anything_personal() {
389
419
let document = finished_call().document();
@@ -384,6 +384,36 @@ mod tests {384
assert!(document.stem.ends_with("-1to1"));384
assert!(document.stem.ends_with("-1to1"));385
}385
}386
386
387
#[test]388
fn each_transfer_answer_settles_the_transfer_it_belongs_to() {389
let mut recorder = recorder();390
let transfer = CallCommand::Transfer {391
target: Callee { mri: PEER_MRI.to_owned(), display_name: "Mara Lindqvist".to_owned() },392
replaces: None,393
};394
recorder.command(&transfer);395
recorder.command(&transfer);396
let entry = |elapsed_ms, label: &str, detail: &str| TimelineEntry { elapsed_ms, label: label.to_owned(), detail: detail.to_owned() };397
recorder.observe(&CallUpdate::Diagnostics(Box::new(CallDiagnostics {398
timeline: vec![399
entry(10, "transfer accepted", "by the target"),400
entry(20, "transfer failed", "code 487 subCode 0"),401
entry(30, "transfer accepted", "by the target"),402
entry(40, "transfer", "completed"),403
],404
..CallDiagnostics::default()405
})));406
let json: serde_json::Value = serde_json::from_str(&recorder.document().json).expect("valid json");407
let transfers: Vec<(&str, &serde_json::Value)> = json["features"]408
.as_array()409
.unwrap()410
.iter()411
.filter(|feature| feature["feature"] == "transfer")412
.map(|feature| (feature["result"].as_str().unwrap(), &feature["confirmed_at_ms"]))413
.collect();414
assert_eq!(transfers, [("failed", &serde_json::Value::Null), ("ok", &serde_json::json!(40))]);415
}416
387
#[test]417
#[test]388
fn neither_file_holds_anything_personal() {418
fn neither_file_holds_anything_personal() {389
let document = finished_call().document();419
let document = finished_call().document();@@ -126,7 +126,7 @@ mod frames {
126
126
use gpui_kit::Entity;
127
127
128
128
use crate::app_state::{AppHandle, AppState, Mode, Selection};
129
use crate::call::{ActiveCall, CallModel};
129
use crate::call::{ActiveCall, CallModel, ConsultCall};
130
130
use crate::demo;
131
131
use crate::user_activity::UserInput;
132
132
use crate::views::call_transcript::TranscriptPanel;
@@ -169,6 +169,11 @@ mod frames {
169
169
"shell/islands/main/prejoin/actions",
170
170
];
171
171
const PREJOIN_LINK: &str = "https://teams.microsoft.com/l/meetup-join/19%3ameeting_guard%40thread.v2/0?context=%7b%22Tid%22%3a%22t%22%2c%22Oid%22%3a%22o%22%7d";
172
const CONSULT_GUARDED: &[&str] = &[
173
"shell/islands/main/call-header/call-consult",
174
"shell/islands/main/call-header/call-consult/transfer",
175
"shell/islands/main/call-header/call-consult/resume",
176
];
172
177
const CALL_TRANSCRIPT: &str = "shell/islands/main/call-transcript";
173
178
const PEOPLE_PANEL: &str = "shell/islands/main/call-people";
174
179
const SHARE_GUARDED: &[&str] = &[
@@ -208,6 +213,7 @@ mod frames {
208
213
CallTranscript,
209
214
CallPeople,
210
215
CallShare,
216
CallConsult,
211
217
}
212
218
213
219
fn parent_of(path: &str) -> Option<&str> {
@@ -331,6 +337,7 @@ mod frames {
331
337
.chain(CALLS_TAGS)
332
338
.chain(PREJOIN_TAGS)
333
339
.chain(SHARE_GUARDED)
340
.chain(CONSULT_GUARDED)
334
341
.chain([
335
342
&CALL_TRANSCRIPT,
336
343
&MENU,
@@ -375,6 +382,24 @@ mod frames {
375
382
ActiveCall::new(1, model, handle.commands, None, handle.video)
376
383
}
377
384
385
fn consult_calls() -> (ActiveCall, ActiveCall) {
386
let connected = |id: u64, name: &str, mri: &str| {
387
let (handle, _control) = call_channel();
388
let mut model = CallModel::people(name, &[(mri.to_owned(), name.to_owned())]);
389
model.apply(CallUpdate::State(CallState::Connected {
390
since: Instant::now(),
391
}));
392
ActiveCall::new(id, model, handle.commands, None, handle.video)
393
};
394
let held = connected(1, "Christopher Montgomery-Lindqvist", "8:orgid:guard-held");
395
let mut consult = connected(2, "Jonas Ortega", "8:orgid:guard-consult");
396
consult.consult = Some(ConsultCall::new(
397
("8:orgid:guard-consult".to_owned(), "Jonas Ortega".to_owned()),
398
held.model.peer_name.clone(),
399
));
400
(consult, held)
401
}
402
378
403
fn mount(cx: &mut TestAppContext) -> (gpui_kit::AnyWindowHandle, Entity<AppState>) {
379
404
mount_with(cx, false)
380
405
}
@@ -477,6 +502,7 @@ mod frames {
477
502
Screen::CallTranscript,
478
503
Screen::CallPeople,
479
504
Screen::CallShare,
505
Screen::CallConsult,
480
506
];
481
507
for screen in screens {
482
508
let (screen_name, status_menu) = match screen {
@@ -540,6 +566,17 @@ mod frames {
540
566
});
541
567
("call-share", false)
542
568
}
569
Screen::CallConsult => {
570
visual.update(|_, cx| {
571
app.update(cx, |state, cx| {
572
let (consult, held) = consult_calls();
573
state.call = Some(consult);
574
state.held_call = Some(held);
575
cx.notify();
576
})
577
});
578
("call-consult", false)
579
}
543
580
Screen::StatusMenu => {
544
581
let tags = collect(&mut visual, None);
545
582
let button = tags
@@ -551,7 +588,10 @@ mod frames {
551
588
("status-menu", true)
552
589
}
553
590
};
554
let is_call = matches!(screen_name, "call" | "call-people" | "call-transcript" | "call-share");
591
let is_call = matches!(
592
screen_name,
593
"call" | "call-people" | "call-transcript" | "call-share" | "call-consult"
594
);
555
595
let tags = collect(&mut visual, status_menu.then_some(MENU));
556
596
let mut expected = GUARDED.to_vec();
557
597
if is_call {
@@ -570,6 +610,9 @@ mod frames {
570
610
if screen_name == "call-share" {
571
611
expected.extend(SHARE_GUARDED);
572
612
}
613
if screen_name == "call-consult" {
614
expected.extend(CONSULT_GUARDED);
615
}
573
616
if status_menu {
574
617
expected.push(MENU);
575
618
}
@@ -607,6 +650,7 @@ mod frames {
607
650
visual.update(|_, cx| {
608
651
app.update(cx, |state, cx| {
609
652
state.call = None;
653
state.held_call = None;
610
654
cx.notify();
611
655
})
612
656
});
@@ -126,7 +126,7 @@ mod frames {126
use gpui_kit::Entity;126
use gpui_kit::Entity;127
127
128
use crate::app_state::{AppHandle, AppState, Mode, Selection};128
use crate::app_state::{AppHandle, AppState, Mode, Selection};129
use crate::call::{ActiveCall, CallModel};129
use crate::call::{ActiveCall, CallModel, ConsultCall};130
use crate::demo;130
use crate::demo;131
use crate::user_activity::UserInput;131
use crate::user_activity::UserInput;132
use crate::views::call_transcript::TranscriptPanel;132
use crate::views::call_transcript::TranscriptPanel;@@ -169,6 +169,11 @@ mod frames {169
"shell/islands/main/prejoin/actions",169
"shell/islands/main/prejoin/actions",170
];170
];171
const PREJOIN_LINK: &str = "https://teams.microsoft.com/l/meetup-join/19%3ameeting_guard%40thread.v2/0?context=%7b%22Tid%22%3a%22t%22%2c%22Oid%22%3a%22o%22%7d";171
const PREJOIN_LINK: &str = "https://teams.microsoft.com/l/meetup-join/19%3ameeting_guard%40thread.v2/0?context=%7b%22Tid%22%3a%22t%22%2c%22Oid%22%3a%22o%22%7d";172
const CONSULT_GUARDED: &[&str] = &[173
"shell/islands/main/call-header/call-consult",174
"shell/islands/main/call-header/call-consult/transfer",175
"shell/islands/main/call-header/call-consult/resume",176
];172
const CALL_TRANSCRIPT: &str = "shell/islands/main/call-transcript";177
const CALL_TRANSCRIPT: &str = "shell/islands/main/call-transcript";173
const PEOPLE_PANEL: &str = "shell/islands/main/call-people";178
const PEOPLE_PANEL: &str = "shell/islands/main/call-people";174
const SHARE_GUARDED: &[&str] = &[179
const SHARE_GUARDED: &[&str] = &[@@ -208,6 +213,7 @@ mod frames {208
CallTranscript,213
CallTranscript,209
CallPeople,214
CallPeople,210
CallShare,215
CallShare,216
CallConsult,211
}217
}212
218
213
fn parent_of(path: &str) -> Option<&str> {219
fn parent_of(path: &str) -> Option<&str> {@@ -331,6 +337,7 @@ mod frames {331
.chain(CALLS_TAGS)337
.chain(CALLS_TAGS)332
.chain(PREJOIN_TAGS)338
.chain(PREJOIN_TAGS)333
.chain(SHARE_GUARDED)339
.chain(SHARE_GUARDED)340
.chain(CONSULT_GUARDED)334
.chain([341
.chain([335
&CALL_TRANSCRIPT,342
&CALL_TRANSCRIPT,336
&MENU,343
&MENU,@@ -375,6 +382,24 @@ mod frames {375
ActiveCall::new(1, model, handle.commands, None, handle.video)382
ActiveCall::new(1, model, handle.commands, None, handle.video)376
}383
}377
384
385
fn consult_calls() -> (ActiveCall, ActiveCall) {386
let connected = |id: u64, name: &str, mri: &str| {387
let (handle, _control) = call_channel();388
let mut model = CallModel::people(name, &[(mri.to_owned(), name.to_owned())]);389
model.apply(CallUpdate::State(CallState::Connected {390
since: Instant::now(),391
}));392
ActiveCall::new(id, model, handle.commands, None, handle.video)393
};394
let held = connected(1, "Christopher Montgomery-Lindqvist", "8:orgid:guard-held");395
let mut consult = connected(2, "Jonas Ortega", "8:orgid:guard-consult");396
consult.consult = Some(ConsultCall::new(397
("8:orgid:guard-consult".to_owned(), "Jonas Ortega".to_owned()),398
held.model.peer_name.clone(),399
));400
(consult, held)401
}402
378
fn mount(cx: &mut TestAppContext) -> (gpui_kit::AnyWindowHandle, Entity<AppState>) {403
fn mount(cx: &mut TestAppContext) -> (gpui_kit::AnyWindowHandle, Entity<AppState>) {379
mount_with(cx, false)404
mount_with(cx, false)380
}405
}@@ -477,6 +502,7 @@ mod frames {477
Screen::CallTranscript,502
Screen::CallTranscript,478
Screen::CallPeople,503
Screen::CallPeople,479
Screen::CallShare,504
Screen::CallShare,505
Screen::CallConsult,480
];506
];481
for screen in screens {507
for screen in screens {482
let (screen_name, status_menu) = match screen {508
let (screen_name, status_menu) = match screen {@@ -540,6 +566,17 @@ mod frames {540
});566
});541
("call-share", false)567
("call-share", false)542
}568
}569
Screen::CallConsult => {570
visual.update(|_, cx| {571
app.update(cx, |state, cx| {572
let (consult, held) = consult_calls();573
state.call = Some(consult);574
state.held_call = Some(held);575
cx.notify();576
})577
});578
("call-consult", false)579
}543
Screen::StatusMenu => {580
Screen::StatusMenu => {544
let tags = collect(&mut visual, None);581
let tags = collect(&mut visual, None);545
let button = tags582
let button = tags@@ -551,7 +588,10 @@ mod frames {551
("status-menu", true)588
("status-menu", true)552
}589
}553
};590
};554
let is_call = matches!(screen_name, "call" | "call-people" | "call-transcript" | "call-share");591
let is_call = matches!(592
screen_name,593
"call" | "call-people" | "call-transcript" | "call-share" | "call-consult"594
);555
let tags = collect(&mut visual, status_menu.then_some(MENU));595
let tags = collect(&mut visual, status_menu.then_some(MENU));556
let mut expected = GUARDED.to_vec();596
let mut expected = GUARDED.to_vec();557
if is_call {597
if is_call {@@ -570,6 +610,9 @@ mod frames {570
if screen_name == "call-share" {610
if screen_name == "call-share" {571
expected.extend(SHARE_GUARDED);611
expected.extend(SHARE_GUARDED);572
}612
}613
if screen_name == "call-consult" {614
expected.extend(CONSULT_GUARDED);615
}573
if status_menu {616
if status_menu {574
expected.push(MENU);617
expected.push(MENU);575
}618
}@@ -607,6 +650,7 @@ mod frames {607
visual.update(|_, cx| {650
visual.update(|_, cx| {608
app.update(cx, |state, cx| {651
app.update(cx, |state, cx| {609
state.call = None;652
state.call = None;653
state.held_call = None;610
cx.notify();654
cx.notify();611
})655
})612
});656
});@@ -164,11 +164,19 @@ pub fn whiteboard_stage(app: &Entity<AppState>, model: &CallModel) -> Option<Any
164
164
}
165
165
166
166
pub fn consult_banner(app: &Entity<AppState>, state: &AppState) -> Option<AnyElement> {
167
let consult = state.call.as_ref()?.consult.as_ref()?;
168
let text = consult.status_text();
169
let ready = consult.ready_to_transfer();
170
let (transfer_app, cancel_app) = (app.clone(), app.clone());
171
let transfer = pill("call-consult-transfer", "Transfer now", true);
167
let call = state.call.as_ref()?;
168
let consult = call.consult.as_ref()?;
169
state.held_call.as_ref()?;
170
let ready = consult.ready_to_transfer(&call.model);
171
let first_name = consult
172
.held_name
173
.split_whitespace()
174
.next()
175
.unwrap_or("call")
176
.to_owned();
177
let (transfer_app, resume_app) = (app.clone(), app.clone());
178
let transfer = pill("call-consult-transfer", "Transfer", true)
179
.debug_selector(|| "shell/islands/main/call-header/call-consult/transfer".into());
172
180
let transfer = if ready {
173
181
transfer.on_click(move |_, _, cx| {
174
182
transfer_app.update(cx, |state, cx| state.transfer_consulted(cx))
@@ -176,9 +184,13 @@ pub fn consult_banner(app: &Entity<AppState>, state: &AppState) -> Option<AnyEle
176
184
} else {
177
185
transfer.opacity(0.5).cursor_default()
178
186
};
187
let resume = pill("call-consult-resume", format!("Resume {first_name}"), false)
188
.debug_selector(|| "shell/islands/main/call-header/call-consult/resume".into())
189
.on_click(move |_, _, cx| resume_app.update(cx, |state, cx| state.resume_held_call(cx)));
179
190
Some(
180
191
h_flex()
181
192
.id("call-consult-banner")
193
.debug_selector(|| "shell/islands/main/call-header/call-consult".into())
182
194
.w_full()
183
195
.h(px(BANNER_HEIGHT))
184
196
.flex_none()
@@ -190,13 +202,9 @@ pub fn consult_banner(app: &Entity<AppState>, state: &AppState) -> Option<AnyEle
190
202
.text_color(dark_text())
191
203
.text_size(px(13.))
192
204
.font_weight(FontWeight::SEMIBOLD)
193
.child(text)
205
.child(div().min_w_0().truncate().child(consult.banner_text()))
194
206
.child(transfer)
195
.child(
196
pill("call-consult-cancel", "Cancel", false).on_click(move |_, _, cx| {
197
cancel_app.update(cx, |state, cx| state.cancel_consult(cx))
198
}),
199
)
207
.child(resume)
200
208
.into_any_element(),
201
209
)
202
210
}
@@ -164,11 +164,19 @@ pub fn whiteboard_stage(app: &Entity<AppState>, model: &CallModel) -> Option<Any164
}164
}165
165
166
pub fn consult_banner(app: &Entity<AppState>, state: &AppState) -> Option<AnyElement> {166
pub fn consult_banner(app: &Entity<AppState>, state: &AppState) -> Option<AnyElement> {167
let consult = state.call.as_ref()?.consult.as_ref()?;167
let call = state.call.as_ref()?;168
let text = consult.status_text();168
let consult = call.consult.as_ref()?;169
let ready = consult.ready_to_transfer();169
state.held_call.as_ref()?;170
let (transfer_app, cancel_app) = (app.clone(), app.clone());170
let ready = consult.ready_to_transfer(&call.model);171
let transfer = pill("call-consult-transfer", "Transfer now", true);171
let first_name = consult172
.held_name173
.split_whitespace()174
.next()175
.unwrap_or("call")176
.to_owned();177
let (transfer_app, resume_app) = (app.clone(), app.clone());178
let transfer = pill("call-consult-transfer", "Transfer", true)179
.debug_selector(|| "shell/islands/main/call-header/call-consult/transfer".into());172
let transfer = if ready {180
let transfer = if ready {173
transfer.on_click(move |_, _, cx| {181
transfer.on_click(move |_, _, cx| {174
transfer_app.update(cx, |state, cx| state.transfer_consulted(cx))182
transfer_app.update(cx, |state, cx| state.transfer_consulted(cx))@@ -176,9 +184,13 @@ pub fn consult_banner(app: &Entity<AppState>, state: &AppState) -> Option<AnyEle176
} else {184
} else {177
transfer.opacity(0.5).cursor_default()185
transfer.opacity(0.5).cursor_default()178
};186
};187
let resume = pill("call-consult-resume", format!("Resume {first_name}"), false)188
.debug_selector(|| "shell/islands/main/call-header/call-consult/resume".into())189
.on_click(move |_, _, cx| resume_app.update(cx, |state, cx| state.resume_held_call(cx)));179
Some(190
Some(180
h_flex()191
h_flex()181
.id("call-consult-banner")192
.id("call-consult-banner")193
.debug_selector(|| "shell/islands/main/call-header/call-consult".into())182
.w_full()194
.w_full()183
.h(px(BANNER_HEIGHT))195
.h(px(BANNER_HEIGHT))184
.flex_none()196
.flex_none()@@ -190,13 +202,9 @@ pub fn consult_banner(app: &Entity<AppState>, state: &AppState) -> Option<AnyEle190
.text_color(dark_text())202
.text_color(dark_text())191
.text_size(px(13.))203
.text_size(px(13.))192
.font_weight(FontWeight::SEMIBOLD)204
.font_weight(FontWeight::SEMIBOLD)193
.child(text)205
.child(div().min_w_0().truncate().child(consult.banner_text()))194
.child(transfer)206
.child(transfer)195
.child(207
.child(resume)196
pill("call-consult-cancel", "Cancel", false).on_click(move |_, _, cx| {197
cancel_app.update(cx, |state, cx| state.cancel_consult(cx))198
}),199
)200
.into_any_element(),208
.into_any_element(),201
)209
)202
}210
}@@ -46,7 +46,7 @@ fn dark_text() -> Hsla {
46
46
hsla(0., 0., 0.08, 1.)
47
47
}
48
48
49
pub(super) fn pill(id: impl Into<ElementId>, label: &'static str, filled: bool) -> Stateful<Div> {
49
pub(super) fn pill(id: impl Into<ElementId>, label: impl Into<SharedString>, filled: bool) -> Stateful<Div> {
50
50
let (background, foreground) = if filled {
51
51
(dark_text(), theme::white())
52
52
} else {
@@ -66,7 +66,7 @@ pub(super) fn pill(id: impl Into<ElementId>, label: &'static str, filled: bool)
66
66
.font_weight(FontWeight::SEMIBOLD)
67
67
.cursor_pointer()
68
68
.hover(|button| button.opacity(0.85))
69
.child(label)
69
.child(label.into())
70
70
}
71
71
72
72
pub fn lobby_text(waiting: usize) -> String {
@@ -46,7 +46,7 @@ fn dark_text() -> Hsla {46
hsla(0., 0., 0.08, 1.)46
hsla(0., 0., 0.08, 1.)47
}47
}48
48
49
pub(super) fn pill(id: impl Into<ElementId>, label: &'static str, filled: bool) -> Stateful<Div> {49
pub(super) fn pill(id: impl Into<ElementId>, label: impl Into<SharedString>, filled: bool) -> Stateful<Div> {50
let (background, foreground) = if filled {50
let (background, foreground) = if filled {51
(dark_text(), theme::white())51
(dark_text(), theme::white())52
} else {52
} else {@@ -66,7 +66,7 @@ pub(super) fn pill(id: impl Into<ElementId>, label: &'static str, filled: bool)66
.font_weight(FontWeight::SEMIBOLD)66
.font_weight(FontWeight::SEMIBOLD)67
.cursor_pointer()67
.cursor_pointer()68
.hover(|button| button.opacity(0.85))68
.hover(|button| button.opacity(0.85))69
.child(label)69
.child(label.into())70
}70
}71
71
72
pub fn lobby_text(waiting: usize) -> String {72
pub fn lobby_text(waiting: usize) -> String {@@ -53,7 +53,7 @@ use crate::signaling::{
53
53
use crate::software_audio::{SoftwareAudio, SoftwareAudioPlan};
54
54
use crate::state::{CallSignal, CallState};
55
55
use crate::timeline::{Timeline, TimelineEntry};
56
use crate::transfer::{TransferEvent, TransferTarget};
56
use crate::transfer::{Replacement, TransferEvent, TransferTarget};
57
57
use crate::video_frame::VideoKey;
58
58
use crate::video_layout::{
59
59
CAMERA_MID, MediaDescription, ONE_TO_ONE_SHARE_MID, SlotTable, VideoLines, VideoRouter, add_one_to_one_lines, add_video_lines, offer_plan, one_to_one_plan,
@@ -854,6 +854,7 @@ async fn drive(
854
854
control.send(CallUpdate::MeetingChat(thread.clone()));
855
855
}
856
856
let mut start_camera_pending = options.start_camera;
857
let mut sent_replacement: Option<Replacement> = None;
857
858
loop {
858
859
if start_camera_pending && video_possible(remote_set, layout, negotiator.path()) {
859
860
start_camera_pending = false;
@@ -884,8 +885,12 @@ async fn drive(
884
885
if layout == Layout::Conference {
885
886
negotiate_video(&mut video, &signaling, control, timeline, &acceptance.sdp, media, acceptance.from_mixer, &media_links, &roster);
886
887
}
887
if let Some(link) = acceptance.links.get("replacement") {
888
control.send(CallUpdate::ReplacementLink(link.clone()));
888
if let Some(link) = acceptance.links.get("replacement")
889
&& sent_replacement.as_ref().is_none_or(|sent| sent.participant_id.is_none())
890
{
891
let replacement = Replacement::of_call(link.clone());
892
sent_replacement = Some(replacement.clone());
893
control.send(CallUpdate::ReplacementLink(replacement));
889
894
}
890
895
if !callee_gate.is_waiting() {
891
896
outgoing_deadline = None;
@@ -1035,6 +1040,12 @@ async fn drive(
1035
1040
report.own_streams = own_streams;
1036
1041
}
1037
1042
send_receive_change(control, video.reselect(&roster));
1043
if let Some(replacement) = roster.transfer_replacement(&own_mri)
1044
&& sent_replacement.as_ref() != Some(&replacement)
1045
{
1046
sent_replacement = Some(replacement.clone());
1047
control.send(CallUpdate::ReplacementLink(replacement));
1048
}
1038
1049
if let Some(in_lobby) = roster.is_in_lobby(&own_mri)
1039
1050
&& in_lobby != lobby
1040
1051
{
@@ -1143,13 +1154,19 @@ async fn drive(
1143
1154
Ok(CallEvent::Transfer(event)) => {
1144
1155
replier.reply(request_id, 200, "");
1145
1156
match event {
1146
TransferEvent::Accepted => timeline.record("transfer", "accepted by the target"),
1157
TransferEvent::Accepted => timeline.record("transfer accepted", "by the target"),
1147
1158
completed if completed.succeeded() => {
1159
timeline.record("transfer", "completed");
1160
control.send(CallUpdate::TransferResult { succeeded: true });
1148
1161
control.send(CallUpdate::Notice("Call transferred".into()));
1149
1162
advance(state, CallSignal::LocalLeave, control);
1150
1163
break;
1151
1164
}
1152
_ => control.send(CallUpdate::Notice("The transfer did not go through".into())),
1165
TransferEvent::Completed { code, sub_code } => {
1166
timeline.record("transfer failed", format!("code {code} subCode {sub_code}"));
1167
control.send(CallUpdate::TransferResult { succeeded: false });
1168
control.send(CallUpdate::Notice("The transfer did not go through".into()));
1169
}
1153
1170
}
1154
1171
}
1155
1172
Ok(CallEvent::Reactions(events)) => {
@@ -1650,14 +1667,16 @@ async fn drive(
1650
1667
}
1651
1668
Some(CallCommand::Transfer { target, replaces }) => {
1652
1669
let Some(url) = media_links.get("transfer").cloned() else {
1670
control.send(CallUpdate::TransferResult { succeeded: false });
1653
1671
control.send(CallUpdate::Notice("This call cannot be transferred".into()));
1654
1672
continue;
1655
1673
};
1656
let transfer_target = TransferTarget { mri: &target.mri, replaces: replaces.as_deref() };
1674
let transfer_target = TransferTarget { mri: &target.mri, replaces: replaces.as_ref() };
1657
1675
match remote.signaling.transfer(&url, &remote.participant, transfer_target, &links).await {
1658
1676
Ok(()) => control.send(CallUpdate::Notice(format!("Transferring to {}...", target.display_name))),
1659
1677
Err(error) => {
1660
1678
timeline.record("transfer failed", error.to_string());
1679
control.send(CallUpdate::TransferResult { succeeded: false });
1661
1680
control.send(CallUpdate::Notice("Could not transfer the call".into()));
1662
1681
}
1663
1682
}
@@ -53,7 +53,7 @@ use crate::signaling::{53
use crate::software_audio::{SoftwareAudio, SoftwareAudioPlan};53
use crate::software_audio::{SoftwareAudio, SoftwareAudioPlan};54
use crate::state::{CallSignal, CallState};54
use crate::state::{CallSignal, CallState};55
use crate::timeline::{Timeline, TimelineEntry};55
use crate::timeline::{Timeline, TimelineEntry};56
use crate::transfer::{TransferEvent, TransferTarget};56
use crate::transfer::{Replacement, TransferEvent, TransferTarget};57
use crate::video_frame::VideoKey;57
use crate::video_frame::VideoKey;58
use crate::video_layout::{58
use crate::video_layout::{59
CAMERA_MID, MediaDescription, ONE_TO_ONE_SHARE_MID, SlotTable, VideoLines, VideoRouter, add_one_to_one_lines, add_video_lines, offer_plan, one_to_one_plan,59
CAMERA_MID, MediaDescription, ONE_TO_ONE_SHARE_MID, SlotTable, VideoLines, VideoRouter, add_one_to_one_lines, add_video_lines, offer_plan, one_to_one_plan,@@ -854,6 +854,7 @@ async fn drive(854
control.send(CallUpdate::MeetingChat(thread.clone()));854
control.send(CallUpdate::MeetingChat(thread.clone()));855
}855
}856
let mut start_camera_pending = options.start_camera;856
let mut start_camera_pending = options.start_camera;857
let mut sent_replacement: Option<Replacement> = None;857
loop {858
loop {858
if start_camera_pending && video_possible(remote_set, layout, negotiator.path()) {859
if start_camera_pending && video_possible(remote_set, layout, negotiator.path()) {859
start_camera_pending = false;860
start_camera_pending = false;@@ -884,8 +885,12 @@ async fn drive(884
if layout == Layout::Conference {885
if layout == Layout::Conference {885
negotiate_video(&mut video, &signaling, control, timeline, &acceptance.sdp, media, acceptance.from_mixer, &media_links, &roster);886
negotiate_video(&mut video, &signaling, control, timeline, &acceptance.sdp, media, acceptance.from_mixer, &media_links, &roster);886
}887
}887
if let Some(link) = acceptance.links.get("replacement") {888
if let Some(link) = acceptance.links.get("replacement")888
control.send(CallUpdate::ReplacementLink(link.clone()));889
&& sent_replacement.as_ref().is_none_or(|sent| sent.participant_id.is_none())890
{891
let replacement = Replacement::of_call(link.clone());892
sent_replacement = Some(replacement.clone());893
control.send(CallUpdate::ReplacementLink(replacement));889
}894
}890
if !callee_gate.is_waiting() {895
if !callee_gate.is_waiting() {891
outgoing_deadline = None;896
outgoing_deadline = None;@@ -1035,6 +1040,12 @@ async fn drive(1035
report.own_streams = own_streams;1040
report.own_streams = own_streams;1036
}1041
}1037
send_receive_change(control, video.reselect(&roster));1042
send_receive_change(control, video.reselect(&roster));1043
if let Some(replacement) = roster.transfer_replacement(&own_mri)1044
&& sent_replacement.as_ref() != Some(&replacement)1045
{1046
sent_replacement = Some(replacement.clone());1047
control.send(CallUpdate::ReplacementLink(replacement));1048
}1038
if let Some(in_lobby) = roster.is_in_lobby(&own_mri)1049
if let Some(in_lobby) = roster.is_in_lobby(&own_mri)1039
&& in_lobby != lobby1050
&& in_lobby != lobby1040
{1051
{@@ -1143,13 +1154,19 @@ async fn drive(1143
Ok(CallEvent::Transfer(event)) => {1154
Ok(CallEvent::Transfer(event)) => {1144
replier.reply(request_id, 200, "");1155
replier.reply(request_id, 200, "");1145
match event {1156
match event {1146
TransferEvent::Accepted => timeline.record("transfer", "accepted by the target"),1157
TransferEvent::Accepted => timeline.record("transfer accepted", "by the target"),1147
completed if completed.succeeded() => {1158
completed if completed.succeeded() => {1159
timeline.record("transfer", "completed");1160
control.send(CallUpdate::TransferResult { succeeded: true });1148
control.send(CallUpdate::Notice("Call transferred".into()));1161
control.send(CallUpdate::Notice("Call transferred".into()));1149
advance(state, CallSignal::LocalLeave, control);1162
advance(state, CallSignal::LocalLeave, control);1150
break;1163
break;1151
}1164
}1152
_ => control.send(CallUpdate::Notice("The transfer did not go through".into())),1165
TransferEvent::Completed { code, sub_code } => {1166
timeline.record("transfer failed", format!("code {code} subCode {sub_code}"));1167
control.send(CallUpdate::TransferResult { succeeded: false });1168
control.send(CallUpdate::Notice("The transfer did not go through".into()));1169
}1153
}1170
}1154
}1171
}1155
Ok(CallEvent::Reactions(events)) => {1172
Ok(CallEvent::Reactions(events)) => {@@ -1650,14 +1667,16 @@ async fn drive(1650
}1667
}1651
Some(CallCommand::Transfer { target, replaces }) => {1668
Some(CallCommand::Transfer { target, replaces }) => {1652
let Some(url) = media_links.get("transfer").cloned() else {1669
let Some(url) = media_links.get("transfer").cloned() else {1670
control.send(CallUpdate::TransferResult { succeeded: false });1653
control.send(CallUpdate::Notice("This call cannot be transferred".into()));1671
control.send(CallUpdate::Notice("This call cannot be transferred".into()));1654
continue;1672
continue;1655
};1673
};1656
let transfer_target = TransferTarget { mri: &target.mri, replaces: replaces.as_deref() };1674
let transfer_target = TransferTarget { mri: &target.mri, replaces: replaces.as_ref() };1657
match remote.signaling.transfer(&url, &remote.participant, transfer_target, &links).await {1675
match remote.signaling.transfer(&url, &remote.participant, transfer_target, &links).await {1658
Ok(()) => control.send(CallUpdate::Notice(format!("Transferring to {}...", target.display_name))),1676
Ok(()) => control.send(CallUpdate::Notice(format!("Transferring to {}...", target.display_name))),1659
Err(error) => {1677
Err(error) => {1660
timeline.record("transfer failed", error.to_string());1678
timeline.record("transfer failed", error.to_string());1679
control.send(CallUpdate::TransferResult { succeeded: false });1661
control.send(CallUpdate::Notice("Could not transfer the call".into()));1680
control.send(CallUpdate::Notice("Could not transfer the call".into()));1662
}1681
}1663
}1682
}@@ -22,6 +22,7 @@ use crate::roster::{MeetingRole, RosterEntry};
22
22
use crate::camera::CameraDevice;
23
23
use crate::screen::ShareSource;
24
24
use crate::signaling::{Callee, MeetingTarget};
25
use crate::transfer::Replacement;
25
26
use crate::state::CallState;
26
27
use crate::video_layout::VideoWant;
27
28
use crate::video_frame::VideoHub;
@@ -72,7 +73,7 @@ pub enum CallCommand {
72
73
SetCaptionLanguage(String),
73
74
ConsentToRecording,
74
75
Hold(bool),
75
Transfer { target: Callee, replaces: Option<String> },
76
Transfer { target: Callee, replaces: Option<Replacement> },
76
77
OpenWhiteboard { title: String },
77
78
Hangup,
78
79
EndMeeting,
@@ -123,7 +124,8 @@ pub enum CallUpdate {
123
124
WhiteboardUrl(String),
124
125
BreakoutMove(BreakoutMove),
125
126
BreakoutRoom { main: MeetingTarget },
126
ReplacementLink(String),
127
ReplacementLink(Replacement),
128
TransferResult { succeeded: bool },
127
129
Capability(MeetingCapability),
128
130
MeetingOptions(std::result::Result<MeetingOptions, String>),
129
131
MeetingOptionsSaved(std::result::Result<MeetingOptions, String>),
@@ -22,6 +22,7 @@ use crate::roster::{MeetingRole, RosterEntry};22
use crate::camera::CameraDevice;22
use crate::camera::CameraDevice;23
use crate::screen::ShareSource;23
use crate::screen::ShareSource;24
use crate::signaling::{Callee, MeetingTarget};24
use crate::signaling::{Callee, MeetingTarget};25
use crate::transfer::Replacement;25
use crate::state::CallState;26
use crate::state::CallState;26
use crate::video_layout::VideoWant;27
use crate::video_layout::VideoWant;27
use crate::video_frame::VideoHub;28
use crate::video_frame::VideoHub;@@ -72,7 +73,7 @@ pub enum CallCommand {72
SetCaptionLanguage(String),73
SetCaptionLanguage(String),73
ConsentToRecording,74
ConsentToRecording,74
Hold(bool),75
Hold(bool),75
Transfer { target: Callee, replaces: Option<String> },76
Transfer { target: Callee, replaces: Option<Replacement> },76
OpenWhiteboard { title: String },77
OpenWhiteboard { title: String },77
Hangup,78
Hangup,78
EndMeeting,79
EndMeeting,@@ -123,7 +124,8 @@ pub enum CallUpdate {123
WhiteboardUrl(String),124
WhiteboardUrl(String),124
BreakoutMove(BreakoutMove),125
BreakoutMove(BreakoutMove),125
BreakoutRoom { main: MeetingTarget },126
BreakoutRoom { main: MeetingTarget },126
ReplacementLink(String),127
ReplacementLink(Replacement),128
TransferResult { succeeded: bool },127
Capability(MeetingCapability),129
Capability(MeetingCapability),128
MeetingOptions(std::result::Result<MeetingOptions, String>),130
MeetingOptions(std::result::Result<MeetingOptions, String>),129
MeetingOptionsSaved(std::result::Result<MeetingOptions, String>),131
MeetingOptionsSaved(std::result::Result<MeetingOptions, String>),@@ -78,6 +78,7 @@ pub use roster::{AttendeeLimits, MeetingRole, PublishedState, RaisedHand, Roster
78
78
pub use sound_capture::LoopbackKind;
79
79
pub use renegotiation::MediaPath;
80
80
pub use signaling::{Callee, MeetingTarget};
81
pub use transfer::Replacement;
81
82
pub use diagnostics::{CallDiagnostics, SdpLine, SdpSummary, StatsSample};
82
83
pub use devices::{AudioDevice, DeviceChoice, DeviceEntry, DeviceLists};
83
84
pub use error::{Error, Result};
@@ -78,6 +78,7 @@ pub use roster::{AttendeeLimits, MeetingRole, PublishedState, RaisedHand, Roster78
pub use sound_capture::LoopbackKind;78
pub use sound_capture::LoopbackKind;79
pub use renegotiation::MediaPath;79
pub use renegotiation::MediaPath;80
pub use signaling::{Callee, MeetingTarget};80
pub use signaling::{Callee, MeetingTarget};81
pub use transfer::Replacement;81
pub use diagnostics::{CallDiagnostics, SdpLine, SdpSummary, StatsSample};82
pub use diagnostics::{CallDiagnostics, SdpLine, SdpSummary, StatsSample};82
pub use devices::{AudioDevice, DeviceChoice, DeviceEntry, DeviceLists};83
pub use devices::{AudioDevice, DeviceChoice, DeviceEntry, DeviceLists};83
pub use error::{Error, Result};84
pub use error::{Error, Result};@@ -1,5 +1,7 @@
1
1
use serde_json::Value;
2
2
3
use crate::transfer::Replacement;
4
3
5
const ACTIVE: &str = "active";
4
6
const AUDIO: &str = "audio";
5
7
const VIDEO: &str = "video";
@@ -82,6 +84,7 @@ pub struct Member {
82
84
pub role: Option<MeetingRole>,
83
85
pub limits: AttendeeLimits,
84
86
pub captions: Option<CaptionBot>,
87
pub replacement: Option<Replacement>,
85
88
version: u64,
86
89
}
87
90
@@ -169,6 +172,13 @@ impl Roster {
169
172
*self != before
170
173
}
171
174
175
pub fn transfer_replacement(&self, own_mri: &str) -> Option<Replacement> {
176
self.members
177
.iter()
178
.filter(|member| member.mri != own_mri && !member.mri.starts_with(BOT_PREFIX) && !member.in_lobby)
179
.find_map(|member| member.replacement.clone())
180
}
181
172
182
pub fn hand_of(&self, mri: &str) -> Option<&RaisedHand> {
173
183
self.members.iter().find(|member| member.mri == mri)?.hand.as_ref()
174
184
}
@@ -279,10 +289,19 @@ fn member_from(mri: &str, participant: &Value, version: u64, previous: Option<&M
279
289
camera_released: published_state(participant, &endpoints, CAMERA_RELEASED),
280
290
},
281
291
captions: mri.starts_with(BOT_PREFIX).then(|| caption_bot(mri, &endpoints)).flatten(),
292
replacement: in_call.iter().copied().chain(&endpoints).find_map(|endpoint| leg_replacement(endpoint)),
282
293
version,
283
294
}
284
295
}
285
296
297
fn leg_replacement(endpoint: &Value) -> Option<Replacement> {
298
let link = endpoint["callLinks"]["replacement"].as_str().filter(|link| !link.is_empty())?;
299
Some(Replacement {
300
link: link.to_owned(),
301
participant_id: endpoint["participantId"].as_str().map(str::to_owned),
302
})
303
}
304
286
305
fn caption_bot(mri: &str, endpoints: &[&Value]) -> Option<CaptionBot> {
287
306
let metadata: Vec<&Value> = endpoints.iter().map(|endpoint| &endpoint["endpointMetadata"]).filter(|metadata| metadata.is_object()).collect();
288
307
let command_url = metadata.iter().find_map(|metadata| metadata["commandUrl"].as_str()).map(str::to_owned);
@@ -694,4 +713,27 @@ mod tests {
694
713
assert_eq!(roster.name_of("abc-123"), Some("Ana"));
695
714
assert_eq!(roster.name_of("zzz"), None);
696
715
}
716
717
#[test]
718
fn the_transfer_replacement_is_the_other_persons_call_leg() {
719
let mut roster = Roster::default();
720
let leg = |participant_id: &str, link: &str| json!({
721
"version": 1,
722
"state": "active",
723
"endpoints": {"ep": {"participantId": participant_id, "callLinks": {"replacement": link}, "call": {}}},
724
});
725
roster.apply(&delta(json!({
726
"8:orgid:me": leg("leg-me", "https://cc/me/replacement"),
727
"28:bot": leg("leg-bot", "https://cc/bot/replacement"),
728
"8:orgid:ana": leg("leg-ana", "https://cc/ana/replacement"),
729
})));
730
assert_eq!(
731
roster.transfer_replacement("8:orgid:me"),
732
Some(Replacement { link: "https://cc/ana/replacement".into(), participant_id: Some("leg-ana".into()) })
733
);
734
assert_eq!(roster.transfer_replacement("8:orgid:ana").map(|replacement| replacement.participant_id), Some(Some("leg-me".into())));
735
let mut without_links = Roster::default();
736
without_links.apply(&delta(json!({"8:orgid:ana": participant("Ana", 1, "active", false, 10)})));
737
assert_eq!(without_links.transfer_replacement("8:orgid:me"), None);
738
}
697
739
}
@@ -1,5 +1,7 @@1
use serde_json::Value;1
use serde_json::Value;2
2
3
use crate::transfer::Replacement;4
3
const ACTIVE: &str = "active";5
const ACTIVE: &str = "active";4
const AUDIO: &str = "audio";6
const AUDIO: &str = "audio";5
const VIDEO: &str = "video";7
const VIDEO: &str = "video";@@ -82,6 +84,7 @@ pub struct Member {82
pub role: Option<MeetingRole>,84
pub role: Option<MeetingRole>,83
pub limits: AttendeeLimits,85
pub limits: AttendeeLimits,84
pub captions: Option<CaptionBot>,86
pub captions: Option<CaptionBot>,87
pub replacement: Option<Replacement>,85
version: u64,88
version: u64,86
}89
}87
90
@@ -169,6 +172,13 @@ impl Roster {169
*self != before172
*self != before170
}173
}171
174
175
pub fn transfer_replacement(&self, own_mri: &str) -> Option<Replacement> {176
self.members177
.iter()178
.filter(|member| member.mri != own_mri && !member.mri.starts_with(BOT_PREFIX) && !member.in_lobby)179
.find_map(|member| member.replacement.clone())180
}181
172
pub fn hand_of(&self, mri: &str) -> Option<&RaisedHand> {182
pub fn hand_of(&self, mri: &str) -> Option<&RaisedHand> {173
self.members.iter().find(|member| member.mri == mri)?.hand.as_ref()183
self.members.iter().find(|member| member.mri == mri)?.hand.as_ref()174
}184
}@@ -279,10 +289,19 @@ fn member_from(mri: &str, participant: &Value, version: u64, previous: Option<&M279
camera_released: published_state(participant, &endpoints, CAMERA_RELEASED),289
camera_released: published_state(participant, &endpoints, CAMERA_RELEASED),280
},290
},281
captions: mri.starts_with(BOT_PREFIX).then(|| caption_bot(mri, &endpoints)).flatten(),291
captions: mri.starts_with(BOT_PREFIX).then(|| caption_bot(mri, &endpoints)).flatten(),292
replacement: in_call.iter().copied().chain(&endpoints).find_map(|endpoint| leg_replacement(endpoint)),282
version,293
version,283
}294
}284
}295
}285
296
297
fn leg_replacement(endpoint: &Value) -> Option<Replacement> {298
let link = endpoint["callLinks"]["replacement"].as_str().filter(|link| !link.is_empty())?;299
Some(Replacement {300
link: link.to_owned(),301
participant_id: endpoint["participantId"].as_str().map(str::to_owned),302
})303
}304
286
fn caption_bot(mri: &str, endpoints: &[&Value]) -> Option<CaptionBot> {305
fn caption_bot(mri: &str, endpoints: &[&Value]) -> Option<CaptionBot> {287
let metadata: Vec<&Value> = endpoints.iter().map(|endpoint| &endpoint["endpointMetadata"]).filter(|metadata| metadata.is_object()).collect();306
let metadata: Vec<&Value> = endpoints.iter().map(|endpoint| &endpoint["endpointMetadata"]).filter(|metadata| metadata.is_object()).collect();288
let command_url = metadata.iter().find_map(|metadata| metadata["commandUrl"].as_str()).map(str::to_owned);307
let command_url = metadata.iter().find_map(|metadata| metadata["commandUrl"].as_str()).map(str::to_owned);@@ -694,4 +713,27 @@ mod tests {694
assert_eq!(roster.name_of("abc-123"), Some("Ana"));713
assert_eq!(roster.name_of("abc-123"), Some("Ana"));695
assert_eq!(roster.name_of("zzz"), None);714
assert_eq!(roster.name_of("zzz"), None);696
}715
}716
717
#[test]718
fn the_transfer_replacement_is_the_other_persons_call_leg() {719
let mut roster = Roster::default();720
let leg = |participant_id: &str, link: &str| json!({721
"version": 1,722
"state": "active",723
"endpoints": {"ep": {"participantId": participant_id, "callLinks": {"replacement": link}, "call": {}}},724
});725
roster.apply(&delta(json!({726
"8:orgid:me": leg("leg-me", "https://cc/me/replacement"),727
"28:bot": leg("leg-bot", "https://cc/bot/replacement"),728
"8:orgid:ana": leg("leg-ana", "https://cc/ana/replacement"),729
})));730
assert_eq!(731
roster.transfer_replacement("8:orgid:me"),732
Some(Replacement { link: "https://cc/ana/replacement".into(), participant_id: Some("leg-ana".into()) })733
);734
assert_eq!(roster.transfer_replacement("8:orgid:ana").map(|replacement| replacement.participant_id), Some(Some("leg-me".into())));735
let mut without_links = Roster::default();736
without_links.apply(&delta(json!({"8:orgid:ana": participant("Ana", 1, "active", false, 10)})));737
assert_eq!(without_links.transfer_replacement("8:orgid:me"), None);738
}697
}739
}@@ -3,10 +3,29 @@ use serde_json::{Value, json};
3
3
use crate::signaling::Participant;
4
4
use crate::trouter_events::CallbackLinks;
5
5
6
#[derive(Debug, Clone, PartialEq, Eq)]
7
pub struct Replacement {
8
pub link: String,
9
pub participant_id: Option<String>,
10
}
11
12
impl Replacement {
13
pub fn of_call(link: impl Into<String>) -> Self {
14
Replacement { link: link.into(), participant_id: None }
15
}
16
17
fn details(&self) -> Value {
18
match &self.participant_id {
19
Some(participant_id) => json!({"replaces": self.link, "replacementTargetParticipantId": participant_id}),
20
None => json!({"replaces": self.link}),
21
}
22
}
23
}
24
6
25
#[derive(Debug, Clone, Copy)]
7
26
pub struct TransferTarget<'a> {
8
27
pub mri: &'a str,
9
pub replaces: Option<&'a str>,
28
pub replaces: Option<&'a Replacement>,
10
29
}
11
30
12
31
fn transferor(from: &Participant) -> Value {
@@ -22,7 +41,7 @@ fn transferor(from: &Participant) -> Value {
22
41
}
23
42
24
43
pub fn transfer_body(from: &Participant, target: TransferTarget<'_>, callbacks: &CallbackLinks) -> Value {
25
let replacement = target.replaces.map(|replaces| json!({"replaces": replaces}));
44
let replacement = target.replaces.map(Replacement::details);
26
45
json!({
27
46
"callTransfer": {
28
47
"target": {"id": target.mri},
@@ -90,8 +109,15 @@ mod tests {
90
109
}
91
110
92
111
#[test]
93
fn a_consulted_transfer_replaces_the_consult_call() {
94
let body = transfer_body(&me(), TransferTarget { mri: "8:orgid:ana", replaces: Some("https://cc.skype.com/replacement") }, &callbacks());
112
fn a_consulted_transfer_replaces_the_consulted_persons_leg() {
113
let leg = Replacement { link: "https://cc.skype.com/leg/replacement".into(), participant_id: Some("leg-7".into()) };
114
let body = transfer_body(&me(), TransferTarget { mri: "8:orgid:ana", replaces: Some(&leg) }, &callbacks());
115
assert_eq!(
116
body["callTransfer"]["replacementDetails"],
117
json!({"replaces": "https://cc.skype.com/leg/replacement", "replacementTargetParticipantId": "leg-7"})
118
);
119
let whole_call = Replacement::of_call("https://cc.skype.com/replacement");
120
let body = transfer_body(&me(), TransferTarget { mri: "8:orgid:ana", replaces: Some(&whole_call) }, &callbacks());
95
121
assert_eq!(body["callTransfer"]["replacementDetails"], json!({"replaces": "https://cc.skype.com/replacement"}));
96
122
}
97
123
@@ -3,10 +3,29 @@ use serde_json::{Value, json};3
use crate::signaling::Participant;3
use crate::signaling::Participant;4
use crate::trouter_events::CallbackLinks;4
use crate::trouter_events::CallbackLinks;5
5
6
#[derive(Debug, Clone, PartialEq, Eq)]7
pub struct Replacement {8
pub link: String,9
pub participant_id: Option<String>,10
}11
12
impl Replacement {13
pub fn of_call(link: impl Into<String>) -> Self {14
Replacement { link: link.into(), participant_id: None }15
}16
17
fn details(&self) -> Value {18
match &self.participant_id {19
Some(participant_id) => json!({"replaces": self.link, "replacementTargetParticipantId": participant_id}),20
None => json!({"replaces": self.link}),21
}22
}23
}24
6
#[derive(Debug, Clone, Copy)]25
#[derive(Debug, Clone, Copy)]7
pub struct TransferTarget<'a> {26
pub struct TransferTarget<'a> {8
pub mri: &'a str,27
pub mri: &'a str,9
pub replaces: Option<&'a str>,28
pub replaces: Option<&'a Replacement>,10
}29
}11
30
12
fn transferor(from: &Participant) -> Value {31
fn transferor(from: &Participant) -> Value {@@ -22,7 +41,7 @@ fn transferor(from: &Participant) -> Value {22
}41
}23
42
24
pub fn transfer_body(from: &Participant, target: TransferTarget<'_>, callbacks: &CallbackLinks) -> Value {43
pub fn transfer_body(from: &Participant, target: TransferTarget<'_>, callbacks: &CallbackLinks) -> Value {25
let replacement = target.replaces.map(|replaces| json!({"replaces": replaces}));44
let replacement = target.replaces.map(Replacement::details);26
json!({45
json!({27
"callTransfer": {46
"callTransfer": {28
"target": {"id": target.mri},47
"target": {"id": target.mri},@@ -90,8 +109,15 @@ mod tests {90
}109
}91
110
92
#[test]111
#[test]93
fn a_consulted_transfer_replaces_the_consult_call() {112
fn a_consulted_transfer_replaces_the_consulted_persons_leg() {94
let body = transfer_body(&me(), TransferTarget { mri: "8:orgid:ana", replaces: Some("https://cc.skype.com/replacement") }, &callbacks());113
let leg = Replacement { link: "https://cc.skype.com/leg/replacement".into(), participant_id: Some("leg-7".into()) };114
let body = transfer_body(&me(), TransferTarget { mri: "8:orgid:ana", replaces: Some(&leg) }, &callbacks());115
assert_eq!(116
body["callTransfer"]["replacementDetails"],117
json!({"replaces": "https://cc.skype.com/leg/replacement", "replacementTargetParticipantId": "leg-7"})118
);119
let whole_call = Replacement::of_call("https://cc.skype.com/replacement");120
let body = transfer_body(&me(), TransferTarget { mri: "8:orgid:ana", replaces: Some(&whole_call) }, &callbacks());95
assert_eq!(body["callTransfer"]["replacementDetails"], json!({"replaces": "https://cc.skype.com/replacement"}));121
assert_eq!(body["callTransfer"]["replacementDetails"], json!({"replaces": "https://cc.skype.com/replacement"}));96
}122
}97
123