| 1 | use calling::{CallEngine, EngineConfig}; |
| 2 | use chatsvc::InstanceNames; |
| 3 | use chrono::{Duration, Utc}; |
| 4 | use serde_json::{Value, json}; |
| 5 | use session::{DEFAULT_ENDPOINT, Method, Scope, Session}; |
| 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 poll_session = Session::connect(&endpoint).await.expect("browser"); |
| 12 | let scope = Scope::graph("OnlineMeetings.ReadWrite"); |
| 13 | let start = Utc::now() + Duration::hours(2); |
| 14 | let body = json!({ |
| 15 | "subject": "Native client test", |
| 16 | "startDateTime": start.to_rfc3339(), |
| 17 | "endDateTime": (start + Duration::minutes(30)).to_rfc3339(), |
| 18 | }); |
| 19 | let created = session |
| 20 | .request( |
| 21 | Method::Post, |
| 22 | "https://graph.microsoft.com/v1.0/me/onlineMeetings", |
| 23 | &scope, |
| 24 | Some(body), |
| 25 | ) |
| 26 | .await |
| 27 | .expect("create"); |
| 28 | println!("# create online meeting: HTTP {}", created.status); |
| 29 | let id = created |
| 30 | .body |
| 31 | .get("id") |
| 32 | .and_then(Value::as_str) |
| 33 | .map(str::to_owned); |
| 34 | let code = created |
| 35 | .body |
| 36 | .pointer("/joinMeetingIdSettings/joinMeetingId") |
| 37 | .and_then(Value::as_str) |
| 38 | .map(|code| code.replace(' ', "")); |
| 39 | let passcode = created |
| 40 | .body |
| 41 | .pointer("/joinMeetingIdSettings/passcode") |
| 42 | .and_then(Value::as_str) |
| 43 | .map(str::to_owned); |
| 44 | let thread = created |
| 45 | .body |
| 46 | .pointer("/chatInfo/threadId") |
| 47 | .and_then(Value::as_str) |
| 48 | .map(str::to_owned); |
| 49 | println!( |
| 50 | "# meeting id found {}, passcode found {}, thread found {}", |
| 51 | code.is_some(), |
| 52 | passcode.is_some(), |
| 53 | thread.is_some() |
| 54 | ); |
| 55 | if let Some(code) = &code { |
| 56 | let config = EngineConfig { |
| 57 | ringable: false, |
| 58 | instance: InstanceNames { |
| 59 | global: "__resolveIdTrouter".into(), |
| 60 | binding: "__resolveIdRealtime".into(), |
| 61 | endpoint_storage_key: "__resolveIdEpid".into(), |
| 62 | }, |
| 63 | ..EngineConfig::default() |
| 64 | }; |
| 65 | let (engine, _events) = CallEngine::start(session.clone(), poll_session, config) |
| 66 | .await |
| 67 | .expect("engine"); |
| 68 | let url = match &passcode { |
| 69 | Some(passcode) => format!("https://teams.microsoft.com/meet/{code}?p={passcode}"), |
| 70 | None => format!("https://teams.microsoft.com/meet/{code}"), |
| 71 | }; |
| 72 | let meeting_data = json!({"meetingCode": code, "passcode": passcode, "meetingUrl": url}); |
| 73 | match engine.resolve_meeting(&meeting_data).await { |
| 74 | Ok(target) => println!( |
| 75 | "# resolve by id: found, same thread {}, tenant and organizer present {}", |
| 76 | thread.as_deref() == Some(target.thread_id.as_str()), |
| 77 | !target.tenant_id.is_empty() && !target.organizer_id.is_empty() |
| 78 | ), |
| 79 | Err(error) => println!( |
| 80 | "# resolve by id: failed: {}", |
| 81 | error.to_string().chars().take(200).collect::<String>() |
| 82 | ), |
| 83 | } |
| 84 | engine.stop().await; |
| 85 | } |
| 86 | if let Some(id) = id { |
| 87 | let deleted = session |
| 88 | .request( |
| 89 | Method::Delete, |
| 90 | &format!("https://graph.microsoft.com/v1.0/me/onlineMeetings/{id}"), |
| 91 | &scope, |
| 92 | None, |
| 93 | ) |
| 94 | .await |
| 95 | .expect("delete"); |
| 96 | println!("# delete online meeting: HTTP {}", deleted.status); |
| 97 | } |
| 98 | } |