fix(calling): a gone incoming call ends as cancelled (#142)
Co-authored-by: Matteo Lombardi <93079933+matteolomba@users.noreply.github.com>
@@ -439,6 +439,12 @@ impl CallEngine {
439
439
advance(&mut state, CallSignal::LocalLeave, &control);
440
440
None
441
441
}
442
Err(error)
443
if accept_found_no_call(&error) && matches!(state, CallState::Connecting) =>
444
{
445
advance(&mut state, CallSignal::LocalLeave, &control);
446
None
447
}
442
448
Err(error) => {
443
449
advance(&mut state, CallSignal::Error(error.to_string()), &control);
444
450
Some(error)
@@ -471,6 +477,18 @@ impl CallEngine {
471
477
}
472
478
}
473
479
480
/// Teams answers 404 when the caller already hung up. While we are still connecting
481
/// that is a cancelled ring, not a failed call.
482
pub(super) fn accept_found_no_call(error: &Error) -> bool {
483
let Error::Signaling(reason) = error else {
484
return false;
485
};
486
let reason = reason.to_ascii_lowercase();
487
reason.contains("post acceptance")
488
&& reason.contains("http 404")
489
&& reason.contains("does not exist")
490
}
491
474
492
async fn setup_step<T, E>(
475
493
control: &mut CallControl,
476
494
step: impl std::future::Future<Output = std::result::Result<T, E>>,
@@ -3073,6 +3091,23 @@ fn far_future() -> Instant {
3073
3091
3074
3092
#[cfg(test)]
3075
3093
mod tests {
3094
#[test]
3095
fn a_missing_call_on_accept_while_connecting_is_a_cancel() {
3096
let gone = Error::Signaling(
3097
"POST acceptance answered HTTP 404 {\"Message\":\"The requested call does not exist.\"}"
3098
.into(),
3099
);
3100
assert!(accept_found_no_call(&gone));
3101
let other = Error::Signaling("POST acceptance answered HTTP 500 boom".into());
3102
assert!(!accept_found_no_call(&other));
3103
let roster = Error::Signaling(
3104
"POST roster answered HTTP 404 {\"Message\":\"The requested call does not exist.\"}"
3105
.into(),
3106
);
3107
assert!(!accept_found_no_call(&roster));
3108
assert!(!accept_found_no_call(&Error::Cancelled));
3109
}
3110
3076
3111
#[test]
3077
3112
fn gathering_settles_shortly_after_a_udp_relay_or_when_complete() {
3078
3113
assert!(!gathering_settled(false, None));
@@ -439,6 +439,12 @@ impl CallEngine {439
advance(&mut state, CallSignal::LocalLeave, &control);439
advance(&mut state, CallSignal::LocalLeave, &control);440
None440
None441
}441
}442
Err(error)443
if accept_found_no_call(&error) && matches!(state, CallState::Connecting) =>444
{445
advance(&mut state, CallSignal::LocalLeave, &control);446
None447
}442
Err(error) => {448
Err(error) => {443
advance(&mut state, CallSignal::Error(error.to_string()), &control);449
advance(&mut state, CallSignal::Error(error.to_string()), &control);444
Some(error)450
Some(error)@@ -471,6 +477,18 @@ impl CallEngine {471
}477
}472
}478
}473
479
480
/// Teams answers 404 when the caller already hung up. While we are still connecting481
/// that is a cancelled ring, not a failed call.482
pub(super) fn accept_found_no_call(error: &Error) -> bool {483
let Error::Signaling(reason) = error else {484
return false;485
};486
let reason = reason.to_ascii_lowercase();487
reason.contains("post acceptance")488
&& reason.contains("http 404")489
&& reason.contains("does not exist")490
}491
474
async fn setup_step<T, E>(492
async fn setup_step<T, E>(475
control: &mut CallControl,493
control: &mut CallControl,476
step: impl std::future::Future<Output = std::result::Result<T, E>>,494
step: impl std::future::Future<Output = std::result::Result<T, E>>,@@ -3073,6 +3091,23 @@ fn far_future() -> Instant {3073
3091
3074
#[cfg(test)]3092
#[cfg(test)]3075
mod tests {3093
mod tests {3094
#[test]3095
fn a_missing_call_on_accept_while_connecting_is_a_cancel() {3096
let gone = Error::Signaling(3097
"POST acceptance answered HTTP 404 {\"Message\":\"The requested call does not exist.\"}"3098
.into(),3099
);3100
assert!(accept_found_no_call(&gone));3101
let other = Error::Signaling("POST acceptance answered HTTP 500 boom".into());3102
assert!(!accept_found_no_call(&other));3103
let roster = Error::Signaling(3104
"POST roster answered HTTP 404 {\"Message\":\"The requested call does not exist.\"}"3105
.into(),3106
);3107
assert!(!accept_found_no_call(&roster));3108
assert!(!accept_found_no_call(&Error::Cancelled));3109
}3110
3076
#[test]3111
#[test]3077
fn gathering_settles_shortly_after_a_udp_relay_or_when_complete() {3112
fn gathering_settles_shortly_after_a_udp_relay_or_when_complete() {3078
assert!(!gathering_settled(false, None));3113
assert!(!gathering_settled(false, None));