BlueGit

ict rusty-teams

Files

rusty-teams / crates / calling / src / trouter_events.rs

trouter_events.rs

trouter_events.rs 21.9 KiB Download Raw
1use std::collections::BTreeMap;
2use std::io::Read;
3
4use base64::Engine;
5use chatsvc::TrouterCallback;
6use flate2::read::GzDecoder;
7use serde_json::{Value, json};
8
9use crate::end::{EndKind, classify_end};
10use crate::error::{Error, Result};
11use crate::reaction::{ReactionEvent, parse_reactions};
12use crate::transfer::{TransferEvent, completion};
13
14const CALLBACK_ROOT: &str = "callAgent/";
15const GZIP_ENCODING: &str = "gzip";
16const MAX_INFLATED_BYTES: u64 = 8 * 1024 * 1024;
17const SPEAKER_KEYS: [&str; 7] = [
18 "csrcs",
19 "csrc",
20 "sources",
21 "sourceIds",
22 "dominantSpeakers",
23 "activeSpeakers",
24 "speakers",
25];
26const MAX_SPEAKER_DEPTH: usize = 4;
27
28const MAX_FIND_DEPTH: usize = 6;
29
30/// First value under `key` anywhere in `value`; Teams nests the same field at different depths.
31pub(crate) fn find_key<'a>(value: &'a Value, key: &str) -> Option<&'a Value> {
32 find_key_within(value, key, 0)
33}
34
35fn find_key_within<'a>(value: &'a Value, key: &str, depth: usize) -> Option<&'a Value> {
36 if depth > MAX_FIND_DEPTH {
37 return None;
38 }
39 match value {
40 Value::Object(map) => map.get(key).or_else(|| map.values().find_map(|child| find_key_within(child, key, depth + 1))),
41 Value::Array(items) => items.iter().find_map(|item| find_key_within(item, key, depth + 1)),
42 _ => None,
43 }
44}
45
46pub fn decode_body(callback: &TrouterCallback) -> Result<Value> {
47 let text = if callback
48 .content_encoding
49 .as_deref()
50 .is_some_and(|encoding| encoding.eq_ignore_ascii_case(GZIP_ENCODING))
51 {
52 inflate(&callback.body)?
53 } else {
54 callback.body.clone()
55 };
56 if text.trim().is_empty() {
57 return Ok(Value::Null);
58 }
59 serde_json::from_str(&text).map_err(|error| Error::Callback(format!("body is not JSON: {error}")))
60}
61
62fn inflate(body: &str) -> Result<String> {
63 let compressed = base64::engine::general_purpose::STANDARD
64 .decode(body.trim())
65 .map_err(|error| Error::Callback(format!("body is not base64: {error}")))?;
66 let mut text = String::new();
67 GzDecoder::new(compressed.as_slice())
68 .take(MAX_INFLATED_BYTES)
69 .read_to_string(&mut text)
70 .map_err(|error| Error::Callback(format!("body is not gzip: {error}")))?;
71 Ok(text)
72}
73
74#[derive(Debug, Clone, PartialEq, Eq)]
75pub struct CallEnd {
76 pub code: i64,
77 pub sub_code: i64,
78 pub phrase: String,
79 pub accepted_elsewhere_by: Option<String>,
80}
81
82impl CallEnd {
83 pub fn kind(&self) -> EndKind {
84 classify_end(self.code, self.sub_code)
85 }
86}
87
88#[derive(Debug, Clone, PartialEq, Eq)]
89pub struct Acceptance {
90 pub sdp: String,
91 pub from_mixer: bool,
92 pub links: BTreeMap<String, String>,
93 pub controller_name: Option<String>,
94 pub keep_alive_seconds: Option<u64>,
95}
96
97impl Acceptance {
98 pub fn in_lobby(&self) -> bool {
99 self.controller_name.as_deref() == Some(LOBBY_CONTROLLER)
100 }
101}
102
103pub const LOBBY_CONTROLLER: &str = "lobby";
104
105#[derive(Debug, Clone, PartialEq, Eq)]
106pub enum ProgressStatus {
107 Ringing,
108 Forwarded,
109 Other(String),
110}
111
112#[derive(Debug, Clone, PartialEq, Eq)]
113pub struct MediaAnswer {
114 pub sdp: String,
115 pub links: BTreeMap<String, String>,
116}
117
118#[derive(Debug, Clone, PartialEq, Eq)]
119pub struct Renegotiation {
120 pub sdp: String,
121 pub new_offer: bool,
122 pub escalation: bool,
123 pub links: BTreeMap<String, String>,
124}
125
126#[derive(Debug, Clone, PartialEq)]
127pub enum CallEvent {
128 ConversationUpdate(Value),
129 RosterUpdate(Value),
130 Acceptance(Acceptance),
131 Progress(ProgressStatus),
132 MediaAnswer(MediaAnswer),
133 MediaRenegotiation(Renegotiation),
134 Speakers(Vec<u32>),
135 AddParticipantSuccess(Value),
136 AddParticipantFailure(Value),
137 Reactions(Vec<ReactionEvent>),
138 LocalParticipantUpdate(Value),
139 Replacement(Value),
140 ContentShareUpdate(Value),
141 ContentShareEnd(Value),
142 Transfer(TransferEvent),
143 End(CallEnd),
144 Other { scope: String, event: String },
145}
146
147impl CallEvent {
148 pub fn name(&self) -> String {
149 match self {
150 CallEvent::ConversationUpdate(_) => "conversation/conversationUpdate".into(),
151 CallEvent::RosterUpdate(_) => "conversation/rosterUpdate".into(),
152 CallEvent::Acceptance(_) => "call/acceptance".into(),
153 CallEvent::Progress(_) => "call/progress".into(),
154 CallEvent::MediaAnswer(_) => "call/mediaAnswer".into(),
155 CallEvent::MediaRenegotiation(_) => "call/mediaRenegotiation".into(),
156 CallEvent::Speakers(_) => "call/speakers".into(),
157 CallEvent::AddParticipantSuccess(_) => "conversation/addParticipantSuccess".into(),
158 CallEvent::AddParticipantFailure(_) => "conversation/addParticipantFailure".into(),
159 CallEvent::Reactions(_) => "conversation/receiveMessage".into(),
160 CallEvent::LocalParticipantUpdate(_) => "conversation/localParticipantUpdate".into(),
161 CallEvent::Replacement(_) => "call/replacement".into(),
162 CallEvent::ContentShareUpdate(_) => "conversation/contentSharingUpdate".into(),
163 CallEvent::ContentShareEnd(_) => "conversation/contentSharingEnd".into(),
164 CallEvent::Transfer(_) => "call/transfer".into(),
165 CallEvent::End(_) => "call/end".into(),
166 CallEvent::Other { scope, event } => format!("{scope}/{event}"),
167 }
168 }
169}
170
171/// `path` is `callAgent/<callId>/<tag>/<call|conversation>/<event>/`.
172pub fn classify(path: &str, body: Value) -> Result<(String, CallEvent)> {
173 let (call_id, scope, event) = split_callback_path(path)?;
174 let event = match (scope.as_str(), event.as_str()) {
175 ("conversation", "conversationUpdate") => CallEvent::ConversationUpdate(body),
176 ("conversation", "rosterUpdate") => CallEvent::RosterUpdate(body),
177 ("conversation", "addParticipantSuccess") => CallEvent::AddParticipantSuccess(body),
178 ("conversation", "receiveMessage") => CallEvent::Reactions(parse_reactions(&body)),
179 ("conversation", "addParticipantFailure") => CallEvent::AddParticipantFailure(body),
180 ("conversation", "localParticipantUpdate") => CallEvent::LocalParticipantUpdate(body),
181 ("conversation", "contentSharingUpdate") => CallEvent::ContentShareUpdate(body),
182 ("conversation", "contentSharingEnd") => CallEvent::ContentShareEnd(body),
183 ("call", "replacement") => CallEvent::Replacement(body),
184 ("call", "transferAcceptance") => CallEvent::Transfer(TransferEvent::Accepted),
185 ("call", "transferCompletion") => CallEvent::Transfer(completion(&body)),
186 ("call", "acceptance") => CallEvent::Acceptance(acceptance(&body)?),
187 ("call", "progress") => CallEvent::Progress(progress(&body)),
188 ("call", "mediaAnswer") => CallEvent::MediaAnswer(media_answer(&body)?),
189 ("call", "mediaRenegotiation") => CallEvent::MediaRenegotiation(renegotiation(&body)?),
190 ("call", "csrcInfo" | "dominantSpeakerInfo") => CallEvent::Speakers(speaker_sources(&body)),
191 ("call", "end") => CallEvent::End(call_end(&body)),
192 (scope, event) => CallEvent::Other {
193 scope: scope.to_owned(),
194 event: event.to_owned(),
195 },
196 };
197 Ok((call_id, event))
198}
199
200pub fn callback_call_id(path: &str) -> Option<String> {
201 split_callback_path(path).ok().map(|(call_id, _, _)| call_id)
202}
203
204fn split_callback_path(path: &str) -> Result<(String, String, String)> {
205 let rest = path
206 .strip_prefix(CALLBACK_ROOT)
207 .ok_or_else(|| Error::Callback(format!("not a call callback: {path}")))?;
208 let parts: Vec<&str> = rest.trim_end_matches('/').split('/').collect();
209 let [call_id, _tag, scope, event] = parts.as_slice() else {
210 return Err(Error::Callback(format!("unexpected callback path shape ({} parts)", parts.len())));
211 };
212 Ok(((*call_id).to_owned(), (*scope).to_owned(), (*event).to_owned()))
213}
214
215fn string_links(value: &Value) -> BTreeMap<String, String> {
216 value
217 .as_object()
218 .map(|links| {
219 links
220 .iter()
221 .filter_map(|(name, url)| Some((name.clone(), url.as_str()?.to_owned())))
222 .collect()
223 })
224 .unwrap_or_default()
225}
226
227fn acceptance(body: &Value) -> Result<Acceptance> {
228 let accepted = &body["callAcceptance"];
229 let media = &accepted["mediaContent"];
230 let sdp = media["blob"]
231 .as_str()
232 .ok_or_else(|| Error::Callback("acceptance without mediaContent.blob".into()))?
233 .to_owned();
234 Ok(Acceptance {
235 sdp,
236 from_mixer: media["fromMixer"].as_bool().unwrap_or(false),
237 links: string_links(&accepted["links"]),
238 controller_name: accepted["controllerName"].as_str().map(str::to_owned),
239 keep_alive_seconds: accepted["callKeepAliveInterval"].as_u64(),
240 })
241}
242
243fn progress(body: &Value) -> ProgressStatus {
244 match body["callProgress"]["status"].as_str().map(str::to_ascii_lowercase).as_deref() {
245 Some("ringing") => ProgressStatus::Ringing,
246 Some("forwarded") => ProgressStatus::Forwarded,
247 other => ProgressStatus::Other(other.unwrap_or_default().to_owned()),
248 }
249}
250
251fn media_answer(body: &Value) -> Result<MediaAnswer> {
252 let answer = &body["mediaAnswer"];
253 let sdp = answer["mediaContent"]["blob"]
254 .as_str()
255 .ok_or_else(|| Error::Callback("mediaAnswer without mediaContent.blob".into()))?
256 .to_owned();
257 Ok(MediaAnswer {
258 sdp,
259 links: string_links(&answer["links"]),
260 })
261}
262
263/// The renegotiation message nests its offer under a key the captures do not show, so any object holding `mediaContent` counts.
264fn media_holder(body: &Value) -> Option<&Value> {
265 if body.get("mediaContent").is_some() {
266 return Some(body);
267 }
268 body.as_object()?.values().find(|value| value.get("mediaContent").is_some())
269}
270
271fn renegotiation(body: &Value) -> Result<Renegotiation> {
272 let holder = media_holder(body)
273 .ok_or_else(|| Error::Callback("mediaRenegotiation without mediaContent".into()))?;
274 let media = &holder["mediaContent"];
275 let sdp = media["blob"]
276 .as_str()
277 .ok_or_else(|| Error::Callback("mediaRenegotiation without mediaContent.blob".into()))?
278 .to_owned();
279 Ok(Renegotiation {
280 sdp,
281 new_offer: media["newOffer"].as_bool().unwrap_or(false),
282 escalation: media["escalationOccurring"].as_bool().unwrap_or(false)
283 || media["isTwoPartyToMultiPartyEscalation"].as_bool().unwrap_or(false),
284 links: string_links(&holder["links"]),
285 })
286}
287
288/// Speaker lists come as arrays of source ids under keys the captures do not show.
289pub fn speaker_sources(body: &Value) -> Vec<u32> {
290 let mut sources = Vec::new();
291 collect_sources(body, 0, &mut sources);
292 sources.sort_unstable();
293 sources.dedup();
294 sources
295}
296
297fn collect_sources(value: &Value, depth: usize, sources: &mut Vec<u32>) {
298 if depth > MAX_SPEAKER_DEPTH {
299 return;
300 }
301 match value {
302 Value::Object(map) => {
303 for (key, child) in map {
304 if SPEAKER_KEYS.contains(&key.as_str()) {
305 push_ids(child, sources);
306 } else {
307 collect_sources(child, depth + 1, sources);
308 }
309 }
310 }
311 Value::Array(items) => items.iter().for_each(|item| collect_sources(item, depth + 1, sources)),
312 _ => {}
313 }
314}
315
316fn push_ids(value: &Value, sources: &mut Vec<u32>) {
317 match value {
318 Value::Number(number) => sources.extend(number.as_u64().and_then(|id| u32::try_from(id).ok())),
319 Value::Array(items) => items.iter().for_each(|item| push_ids(item, sources)),
320 Value::Object(map) => {
321 if let Some(id) = map.get("sourceId") {
322 push_ids(id, sources);
323 }
324 }
325 _ => {}
326 }
327}
328
329fn call_end(body: &Value) -> CallEnd {
330 let end = &body["callEnd"];
331 CallEnd {
332 code: end["code"].as_i64().unwrap_or_default(),
333 sub_code: end["subCode"].as_i64().unwrap_or_default(),
334 phrase: end["phrase"].as_str().unwrap_or_default().to_owned(),
335 accepted_elsewhere_by: end["acceptedElsewhereBy"]["displayName"]
336 .as_str()
337 .or_else(|| end["acceptedElsewhereBy"]["id"].as_str())
338 .map(str::to_owned),
339 }
340}
341
342/// Callback URLs the client invents under its Trouter `surl`; Trouter routes them to the socket without registration.
343#[derive(Debug, Clone)]
344pub struct CallbackLinks {
345 base: String,
346 call_id: String,
347}
348
349impl CallbackLinks {
350 pub fn new(surl: &str, call_id: &str) -> Self {
351 let mut base = surl.to_owned();
352 if !base.ends_with('/') {
353 base.push('/');
354 }
355 CallbackLinks {
356 base,
357 call_id: call_id.to_owned(),
358 }
359 }
360
361 pub fn call_id(&self) -> &str {
362 &self.call_id
363 }
364
365 pub fn link(&self, scope: &str, event: &str) -> String {
366 let tag = &uuid::Uuid::new_v4().simple().to_string()[..8];
367 format!("{}{CALLBACK_ROOT}{}/{tag}/{scope}/{event}/", self.base, self.call_id)
368 }
369
370 pub fn conversation(&self, event: &str) -> String {
371 self.link("conversation", event)
372 }
373
374 pub fn call(&self, event: &str) -> String {
375 self.link("call", event)
376 }
377}
378
379pub fn acceptance_acknowledgement(links: &CallbackLinks) -> Value {
380 json!({"callAcceptanceAcknowledgement": {"links": acceptance_links(links)}})
381}
382
383pub fn acceptance_links(links: &CallbackLinks) -> serde_json::Map<String, Value> {
384 let names = [
385 "mediaRenegotiation",
386 "transfer",
387 "replacement",
388 "balanceUpdate",
389 "retargetCompletion",
390 "controlVideoStreaming",
391 "updateMediaDescriptions",
392 ];
393 names
394 .into_iter()
395 .map(|name| (name.to_owned(), Value::String(links.call(name))))
396 .collect()
397}
398
399#[cfg(test)]
400mod tests {
401 use std::io::Write;
402
403 use flate2::Compression;
404 use flate2::write::GzEncoder;
405
406 use super::*;
407
408 fn gzip_base64(text: &str) -> String {
409 let mut encoder = GzEncoder::new(Vec::new(), Compression::default());
410 encoder.write_all(text.as_bytes()).unwrap();
411 base64::engine::general_purpose::STANDARD.encode(encoder.finish().unwrap())
412 }
413
414 fn callback(path: &str, body: &str, gzip: bool) -> TrouterCallback {
415 TrouterCallback {
416 request_id: 1,
417 path: path.into(),
418 content_encoding: gzip.then(|| "gzip".into()),
419 body: if gzip { gzip_base64(body) } else { body.into() },
420 }
421 }
422
423 #[test]
424 fn gzip_base64_bodies_decode_to_json() {
425 let body = r#"{"callEnd":{"code":0,"subCode":0,"phrase":"CallEndReasonLocalUserInitiated"}}"#;
426 let decoded = decode_body(&callback("callAgent/c/1/call/end/", body, true)).unwrap();
427 assert_eq!(decoded["callEnd"]["phrase"], "CallEndReasonLocalUserInitiated");
428 let plain = decode_body(&callback("callAgent/c/1/call/end/", body, false)).unwrap();
429 assert_eq!(plain, decoded);
430 }
431
432 #[test]
433 fn classifies_acceptance_with_sdp_and_links() {
434 let body = json!({"callAcceptance": {"mediaContent": {"blob": "v=0\r\n", "fromMixer": true},
435 "links": {"acknowledgement": "https://cc/ack", "callLeg": "https://cc/leg"}}});
436 let (call_id, event) = classify("callAgent/abc/dbea1786/call/acceptance/", body).unwrap();
437 assert_eq!(call_id, "abc");
438 let CallEvent::Acceptance(acceptance) = event else { panic!("not acceptance") };
439 assert_eq!(acceptance.sdp, "v=0\r\n");
440 assert!(acceptance.from_mixer);
441 assert_eq!(acceptance.links["callLeg"], "https://cc/leg");
442 }
443
444 #[test]
445 fn classifies_the_events_of_the_last_features() {
446 let (_, update) = classify("callAgent/abc/1/conversation/localParticipantUpdate/", json!({"breakoutDetails": {}})).unwrap();
447 assert!(matches!(update, CallEvent::LocalParticipantUpdate(_)));
448 let (_, replacement) = classify("callAgent/abc/1/call/replacement/", json!({"callNotification": {}})).unwrap();
449 assert_eq!(replacement.name(), "call/replacement");
450 let (_, share) = classify("callAgent/abc/1/conversation/contentSharingUpdate/", json!({"sessionState": {}})).unwrap();
451 assert!(matches!(share, CallEvent::ContentShareUpdate(_)));
452 let (_, ended) = classify("callAgent/abc/1/conversation/contentSharingEnd/", Value::Null).unwrap();
453 assert!(matches!(ended, CallEvent::ContentShareEnd(_)));
454 let (_, accepted) = classify("callAgent/abc/1/call/transferAcceptance/", Value::Null).unwrap();
455 assert_eq!(accepted, CallEvent::Transfer(TransferEvent::Accepted));
456 let (_, completed) = classify("callAgent/abc/1/call/transferCompletion/", json!({"transferCompletion": {"code": 0}})).unwrap();
457 assert!(matches!(completed, CallEvent::Transfer(event) if event.succeeded()));
458 }
459
460 #[test]
461 fn classifies_end_and_unknown_events() {
462 let (_, end) = classify("callAgent/abc/1/call/end/", json!({"callEnd": {"code": 0, "subCode": 5, "phrase": "x"}})).unwrap();
463 assert_eq!(end, CallEvent::End(CallEnd { code: 0, sub_code: 5, phrase: "x".into(), accepted_elsewhere_by: None }));
464 let (_, other) = classify("callAgent/abc/1/call/updateMediaDescriptions", Value::Null).unwrap();
465 assert_eq!(other.name(), "call/updateMediaDescriptions");
466 assert!(classify("unifiedPresenceService", Value::Null).is_err());
467 }
468
469 #[test]
470 fn links_live_under_the_socket_url() {
471 let links = CallbackLinks::new("https://pub-ent-euwe-02-f.trouter.teams.microsoft.com:3443/v4/f/abc", "call-1");
472 let link = links.call("acceptance");
473 assert!(link.starts_with("https://pub-ent-euwe-02-f.trouter.teams.microsoft.com:3443/v4/f/abc/callAgent/call-1/"));
474 assert!(link.ends_with("/call/acceptance/"));
475 let acknowledgement = acceptance_acknowledgement(&links);
476 assert!(acknowledgement["callAcceptanceAcknowledgement"]["links"]["mediaRenegotiation"]
477 .as_str()
478 .unwrap()
479 .ends_with("/call/mediaRenegotiation/"));
480 }
481 #[test]
482 fn progress_reports_ringing_and_forwarding() {
483 let ringing = json!({"callProgress": {"sender": "x", "status": "ringing", "phrase": "ringing"}});
484 let (_, event) = classify("callAgent/abc/1/call/progress/", ringing).unwrap();
485 assert_eq!(event, CallEvent::Progress(ProgressStatus::Ringing));
486 let forwarded = json!({"callProgress": {"status": "forwarded"}});
487 let (_, event) = classify("callAgent/abc/1/call/progress/", forwarded).unwrap();
488 assert_eq!(event, CallEvent::Progress(ProgressStatus::Forwarded));
489 let (_, other) = classify("callAgent/abc/1/call/progress/", json!({})).unwrap();
490 assert_eq!(other, CallEvent::Progress(ProgressStatus::Other(String::new())));
491 }
492
493 #[test]
494 fn provisional_answers_carry_sdp_and_links() {
495 let body = json!({"mediaAnswer": {"sender": "x", "mediaContent": {"blob": "v=0\r\n"},
496 "links": {"mediaAcknowledgement": "https://cc/ack"}}});
497 let (_, event) = classify("callAgent/abc/1/call/mediaAnswer/", body).unwrap();
498 let CallEvent::MediaAnswer(answer) = event else { panic!("not a media answer") };
499 assert_eq!(answer.sdp, "v=0\r\n");
500 assert_eq!(answer.links["mediaAcknowledgement"], "https://cc/ack");
501 assert!(classify("callAgent/abc/1/call/mediaAnswer/", json!({})).is_err());
502 }
503
504 #[test]
505 fn renegotiation_finds_its_offer_under_any_key() {
506 let nested = json!({"mediaNegotiation": {"mediaContent": {"blob": "v=0\r\n", "newOffer": true,
507 "escalationOccurring": true}, "links": {"mediaAnswer": "https://cc/answer"}}});
508 let (_, event) = classify("callAgent/abc/1/call/mediaRenegotiation/", nested).unwrap();
509 let CallEvent::MediaRenegotiation(renegotiation) = event else { panic!("not a renegotiation") };
510 assert!(renegotiation.new_offer && renegotiation.escalation);
511 assert_eq!(renegotiation.links["mediaAnswer"], "https://cc/answer");
512 let flat = json!({"mediaContent": {"blob": "v=0\r\n", "isTwoPartyToMultiPartyEscalation": true}});
513 let (_, event) = classify("callAgent/abc/1/call/mediaRenegotiation/", flat).unwrap();
514 let CallEvent::MediaRenegotiation(renegotiation) = event else { panic!("not a renegotiation") };
515 assert!(!renegotiation.new_offer && renegotiation.escalation);
516 assert!(classify("callAgent/abc/1/call/mediaRenegotiation/", json!({"x": 1})).is_err());
517 }
518
519 #[test]
520 fn speaker_sources_come_from_known_list_keys() {
521 assert_eq!(speaker_sources(&json!({"csrcInfo": {"csrcs": [201, 205, 201]}})), vec![201, 205]);
522 assert_eq!(speaker_sources(&json!({"dominantSpeakers": [{"sourceId": 7}]})), vec![7]);
523 assert!(speaker_sources(&json!({"other": [1, 2]})).is_empty());
524 let (_, event) = classify("callAgent/abc/1/call/csrcInfo/", json!({"sources": [3]})).unwrap();
525 assert_eq!(event, CallEvent::Speakers(vec![3]));
526 }
527
528 #[test]
529 fn end_names_who_answered_elsewhere() {
530 let body = json!({"callEnd": {"code": 450, "subCode": 0, "phrase": "x",
531 "acceptedElsewhereBy": {"id": "8:orgid:1", "displayName": "Daniel"}}});
532 let (_, event) = classify("callAgent/abc/1/call/end/", body).unwrap();
533 let CallEvent::End(end) = event else { panic!("not an end") };
534 assert_eq!(end.kind(), EndKind::AnsweredElsewhere);
535 assert_eq!(end.accepted_elsewhere_by.as_deref(), Some("Daniel"));
536 }
537
538 #[test]
539 fn acceptance_in_the_lobby_is_flagged() {
540 let body = json!({"callAcceptance": {"controllerName": "lobby", "callKeepAliveInterval": 2700,
541 "mediaContent": {"blob": "v=0\r\n"}}});
542 let (_, event) = classify("callAgent/abc/1/call/acceptance/", body).unwrap();
543 let CallEvent::Acceptance(acceptance) = event else { panic!("not acceptance") };
544 assert!(acceptance.in_lobby());
545 assert_eq!(acceptance.keep_alive_seconds, Some(2700));
546 }
547
548 #[test]
549 fn call_ids_come_from_the_path_alone() {
550 assert_eq!(callback_call_id("callAgent/abc/1/call/end/").as_deref(), Some("abc"));
551 assert_eq!(callback_call_id("unifiedPresenceService"), None);
552 assert_eq!(callback_call_id(""), None);
553 }
554}