BlueGit

ict rusty-teams

fix(calls): cancel reacts while the call is still being set up

- camera list loads in the background instead of blocking the offer
- creating the offer is cancellable, so Cancel no longer waits for setup
- call report times the camera list and the offer
- new example cleanup_test_chats hides the "Native client test" meeting chats after live tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-07 · 3 weeks ago

Hash
af8e6479ca41fe4a0fe097b356d50d15371a8578
Parent
0f749ccd
2 files changed +62 −2
crates/calling/examples/cleanup_test_chats.rs added +47 −0
@@ -0,0 +1,47 @@
1 use serde_json::{Value, json};
2 use session::{DEFAULT_ENDPOINT, Method, Scope, Session};
3
4 const SUBJECT: &str = "Native client test";
5 const GRAPH: &str = "https://graph.microsoft.com/v1.0";
6
7 #[tokio::main]
8 async fn main() {
9 let endpoint = std::env::var("CDP_ENDPOINT").unwrap_or_else(|_| DEFAULT_ENDPOINT.to_owned());
10 let session = Session::connect(&endpoint).await.expect("browser");
11 let scope = Scope::graph("Chat.ReadWrite");
12 let me = session
13 .request(Method::Get, &format!("{GRAPH}/me?$select=id"), &scope, None)
14 .await
15 .expect("me");
16 let organization = session
17 .request(Method::Get, &format!("{GRAPH}/organization?$select=id"), &scope, None)
18 .await
19 .expect("organization");
20 let user = json!({
21 "id": me.body.get("id").and_then(Value::as_str).unwrap_or_default(),
22 "tenantId": organization.body.pointer("/value/0/id").and_then(Value::as_str).unwrap_or_default(),
23 });
24 let mut next = Some(format!(
25 "{GRAPH}/me/chats?$select=id,topic&$filter=topic eq '{SUBJECT}'&$top=50"
26 ));
27 let mut hidden = 0;
28 while let Some(url) = next.take() {
29 let page = session.request(Method::Get, &url, &scope, None).await.expect("list");
30 let chats = page.body.get("value").and_then(Value::as_array).cloned().unwrap_or_default();
31 for chat in chats {
32 if chat.get("topic").and_then(Value::as_str) != Some(SUBJECT) {
33 continue;
34 }
35 let id = chat.get("id").and_then(Value::as_str).unwrap_or_default();
36 let hide_url = format!("{GRAPH}/chats/{id}/hideForUser");
37 let answer = session
38 .request(Method::Post, &hide_url, &scope, Some(json!({ "user": user })))
39 .await
40 .expect("hide");
41 println!("# hide test meeting chat: HTTP {}", answer.status);
42 hidden += 1;
43 }
44 next = page.body.get("@odata.nextLink").and_then(Value::as_str).map(str::to_owned);
45 }
46 println!("# hid {hidden} test meeting chat(s)");
47 }
@@ -0,0 +1,47 @@
1use serde_json::{Value, json};
2use session::{DEFAULT_ENDPOINT, Method, Scope, Session};
3
4const SUBJECT: &str = "Native client test";
5const GRAPH: &str = "https://graph.microsoft.com/v1.0";
6
7#[tokio::main]
8async fn main() {
9 let endpoint = std::env::var("CDP_ENDPOINT").unwrap_or_else(|_| DEFAULT_ENDPOINT.to_owned());
10 let session = Session::connect(&endpoint).await.expect("browser");
11 let scope = Scope::graph("Chat.ReadWrite");
12 let me = session
13 .request(Method::Get, &format!("{GRAPH}/me?$select=id"), &scope, None)
14 .await
15 .expect("me");
16 let organization = session
17 .request(Method::Get, &format!("{GRAPH}/organization?$select=id"), &scope, None)
18 .await
19 .expect("organization");
20 let user = json!({
21 "id": me.body.get("id").and_then(Value::as_str).unwrap_or_default(),
22 "tenantId": organization.body.pointer("/value/0/id").and_then(Value::as_str).unwrap_or_default(),
23 });
24 let mut next = Some(format!(
25 "{GRAPH}/me/chats?$select=id,topic&$filter=topic eq '{SUBJECT}'&$top=50"
26 ));
27 let mut hidden = 0;
28 while let Some(url) = next.take() {
29 let page = session.request(Method::Get, &url, &scope, None).await.expect("list");
30 let chats = page.body.get("value").and_then(Value::as_array).cloned().unwrap_or_default();
31 for chat in chats {
32 if chat.get("topic").and_then(Value::as_str) != Some(SUBJECT) {
33 continue;
34 }
35 let id = chat.get("id").and_then(Value::as_str).unwrap_or_default();
36 let hide_url = format!("{GRAPH}/chats/{id}/hideForUser");
37 let answer = session
38 .request(Method::Post, &hide_url, &scope, Some(json!({ "user": user })))
39 .await
40 .expect("hide");
41 println!("# hide test meeting chat: HTTP {}", answer.status);
42 hidden += 1;
43 }
44 next = page.body.get("@odata.nextLink").and_then(Value::as_str).map(str::to_owned);
45 }
46 println!("# hid {hidden} test meeting chat(s)");
47}
crates/calling/src/call.rs +15 −2
@@ -780,7 +780,7 @@ async fn drive(
780 780 let mut local_video = LocalVideo::new(&factory, options.video, control.video.clone(), control.updates());
781 781 let mut camera_choice = options.camera.clone();
782 782 let mut media_description_request = 1u32;
783 control.send(CallUpdate::Cameras(camera_devices(options.video).await));
783 refresh_cameras(control.updates(), options.video, timeline.clone());
784 784 refresh_share_sources(control.updates(), options.video);
785 785
786 786 let wants_data_channel = options.data_channel && spec.as_ref().is_some_and(CallSpec::is_meeting);
@@ -834,7 +834,11 @@ async fn drive(
834 834 let conversation = match (spec, incoming_media) {
835 835 (Some(spec), None) => {
836 836 let direct_invite = spec.target().is_one_to_one() && !options.concurrent;
837 let media = create_offer(&current.peer, &factory, &track, layout, direct_invite.then_some(&current.gathered)).await?;
837 let offer_started = Instant::now();
838 let media = control
839 .until_hangup(create_offer(&current.peer, &factory, &track, layout, direct_invite.then_some(&current.gathered)))
840 .await??;
841 timeline.record("offer created", format!("{} ms", offer_started.elapsed().as_millis()));
838 842 layout_plan = media.plan.clone();
839 843 if layout == Layout::OneToOne {
840 844 direct_video_mid = Some(CAMERA_MID.to_owned());
@@ -2591,6 +2595,15 @@ async fn camera_devices(mode: VideoMode) -> Vec<CameraDevice> {
2591 2595 }
2592 2596 }
2593 2597
2598 fn refresh_cameras(updates: mpsc::UnboundedSender<CallUpdate>, mode: VideoMode, timeline: Timeline) {
2599 tokio::spawn(async move {
2600 let started = Instant::now();
2601 let cameras = camera_devices(mode).await;
2602 timeline.record("camera list", format!("{} camera(s) in {} ms", cameras.len(), started.elapsed().as_millis()));
2603 let _ = updates.send(CallUpdate::Cameras(cameras));
2604 });
2605 }
2606
2594 2607 fn refresh_share_sources(updates: mpsc::UnboundedSender<CallUpdate>, mode: VideoMode) {
2595 2608 tokio::spawn(async move {
2596 2609 let sources = match mode {
@@ -780,7 +780,7 @@ async fn drive(
780 let mut local_video = LocalVideo::new(&factory, options.video, control.video.clone(), control.updates());
780 let mut local_video = LocalVideo::new(&factory, options.video, control.video.clone(), control.updates());
781 let mut camera_choice = options.camera.clone();
781 let mut camera_choice = options.camera.clone();
782 let mut media_description_request = 1u32;
782 let mut media_description_request = 1u32;
783 control.send(CallUpdate::Cameras(camera_devices(options.video).await));
783 refresh_cameras(control.updates(), options.video, timeline.clone());
784 refresh_share_sources(control.updates(), options.video);
784 refresh_share_sources(control.updates(), options.video);
785
785
786 let wants_data_channel = options.data_channel && spec.as_ref().is_some_and(CallSpec::is_meeting);
786 let wants_data_channel = options.data_channel && spec.as_ref().is_some_and(CallSpec::is_meeting);
@@ -834,7 +834,11 @@ async fn drive(
834 let conversation = match (spec, incoming_media) {
834 let conversation = match (spec, incoming_media) {
835 (Some(spec), None) => {
835 (Some(spec), None) => {
836 let direct_invite = spec.target().is_one_to_one() && !options.concurrent;
836 let direct_invite = spec.target().is_one_to_one() && !options.concurrent;
837 let media = create_offer(&current.peer, &factory, &track, layout, direct_invite.then_some(&current.gathered)).await?;
837 let offer_started = Instant::now();
838 let media = control
839 .until_hangup(create_offer(&current.peer, &factory, &track, layout, direct_invite.then_some(&current.gathered)))
840 .await??;
841 timeline.record("offer created", format!("{} ms", offer_started.elapsed().as_millis()));
838 layout_plan = media.plan.clone();
842 layout_plan = media.plan.clone();
839 if layout == Layout::OneToOne {
843 if layout == Layout::OneToOne {
840 direct_video_mid = Some(CAMERA_MID.to_owned());
844 direct_video_mid = Some(CAMERA_MID.to_owned());
@@ -2591,6 +2595,15 @@ async fn camera_devices(mode: VideoMode) -> Vec<CameraDevice> {
2591 }
2595 }
2592}
2596}
2593
2597
2598fn refresh_cameras(updates: mpsc::UnboundedSender<CallUpdate>, mode: VideoMode, timeline: Timeline) {
2599 tokio::spawn(async move {
2600 let started = Instant::now();
2601 let cameras = camera_devices(mode).await;
2602 timeline.record("camera list", format!("{} camera(s) in {} ms", cameras.len(), started.elapsed().as_millis()));
2603 let _ = updates.send(CallUpdate::Cameras(cameras));
2604 });
2605}
2606
2594fn refresh_share_sources(updates: mpsc::UnboundedSender<CallUpdate>, mode: VideoMode) {
2607fn refresh_share_sources(updates: mpsc::UnboundedSender<CallUpdate>, mode: VideoMode) {
2595 tokio::spawn(async move {
2608 tokio::spawn(async move {
2596 let sources = match mode {
2609 let sources = match mode {