fix(calls): hold no longer ends a mixer-routed call
- Renegotiation offers copied libwebrtc's gathered candidates (tcptype, IPv6, generation/network-id) into the Teams SDP; the mixer rejected them with 410/301000 SdpParsingFailure. Only the placeholder candidate is signaled now, as in the first offer. - libwebrtc never restarts an audio send stream that an inactive answer stopped. A hold now signals inactive to Teams but keeps the local streams running and mutes the outgoing audio until resume. - echo_call example: --hold holds for 10 s and resumes. Verified live with the Echo bot: hold, 10 s, resume; call stays up, audio flows both ways after resume. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -2,11 +2,14 @@ use std::path::PathBuf;
2
2
use std::time::Duration;
3
3
4
4
use calling::audio_io::AUDIO_MODE_ENV;
5
use calling::{AudioMode, CallOptions, CallReport, call_channel, run_test_call};
5
use calling::{AudioMode, CallCommand, CallOptions, CallReport, CallState, CallUpdate, call_channel, run_test_call};
6
6
use session::{DEFAULT_ENDPOINT, Session};
7
7
8
8
const HOLD_AFTER_CONNECTED: Duration = Duration::from_secs(12);
9
9
const HARD_LIMIT: Duration = Duration::from_secs(20);
10
const HOLD_START: Duration = Duration::from_secs(4);
11
const HOLD_LENGTH: Duration = Duration::from_secs(10);
12
const AFTER_RESUME: Duration = Duration::from_secs(20);
10
13
11
14
fn print_report(report: &CallReport) {
12
15
println!("# ice connected at {:?} ms, peer connected at {:?} ms", report.ice_connected_ms, report.peer_connected_ms);
@@ -42,6 +45,7 @@ async fn main() {
42
45
let session = Session::connect(&endpoint).await.expect("browser");
43
46
let poll_session = Session::connect(&endpoint).await.expect("browser");
44
47
let audio = AudioMode::parse(Some(&std::env::var(AUDIO_MODE_ENV).unwrap_or_else(|_| "tone".to_owned())));
48
let hold = std::env::args().any(|argument| argument == "--hold");
45
49
let rounds: usize = std::env::args().skip_while(|argument| argument != "--rounds").nth(1).and_then(|value| value.parse().ok()).unwrap_or(1);
46
50
for round in 1..=rounds {
47
51
println!("# round {round} of {rounds}");
@@ -49,15 +53,16 @@ async fn main() {
49
53
(Some(path), 2..) => Some(path.with_extension(format!("{round}.wav"))),
50
54
_ => wav_path.clone(),
51
55
};
52
test_call(&session, &poll_session, audio, round_wav).await;
56
test_call(&session, &poll_session, audio, round_wav, hold).await;
53
57
}
54
58
}
55
59
56
async fn test_call(session: &Session, poll_session: &Session, audio: AudioMode, wav_path: Option<PathBuf>) {
60
async fn test_call(session: &Session, poll_session: &Session, audio: AudioMode, wav_path: Option<PathBuf>, hold: bool) {
61
let connected_for = if hold { HOLD_START + HOLD_LENGTH + AFTER_RESUME } else { HOLD_AFTER_CONNECTED };
57
62
let options = CallOptions {
58
63
audio,
59
hold_after_connected: Some(HOLD_AFTER_CONNECTED),
60
hard_limit: Some(HARD_LIMIT),
64
hold_after_connected: Some(connected_for),
65
hard_limit: Some(connected_for + HARD_LIMIT - HOLD_AFTER_CONNECTED),
61
66
record_remote: true,
62
67
wav_path: wav_path.clone(),
63
68
sdp_dump_dir: std::env::var("CALLING_SDP_DUMP").ok().map(PathBuf::from),
@@ -66,10 +71,32 @@ async fn test_call(session: &Session, poll_session: &Session, audio: AudioMode,
66
71
};
67
72
println!(
68
73
"# Test call, audio {:?}, hang up after {:?} connected (hard limit {:?})",
69
options.audio, HOLD_AFTER_CONNECTED, HARD_LIMIT
74
options.audio, options.hold_after_connected, options.hard_limit
70
75
);
71
76
let (mut handle, control) = call_channel();
72
let drain = tokio::spawn(async move { while handle.updates.recv().await.is_some() {} });
77
let commands = handle.commands.clone();
78
let drain = tokio::spawn(async move {
79
let mut hold_scheduled = !hold;
80
while let Some(update) = handle.updates.recv().await {
81
match update {
82
CallUpdate::State(CallState::Connected { .. }) if !hold_scheduled => {
83
hold_scheduled = true;
84
let commands = commands.clone();
85
tokio::spawn(async move {
86
tokio::time::sleep(HOLD_START).await;
87
println!("# hold");
88
let _ = commands.send(CallCommand::Hold(true));
89
tokio::time::sleep(HOLD_LENGTH).await;
90
println!("# resume");
91
let _ = commands.send(CallCommand::Hold(false));
92
});
93
}
94
CallUpdate::Hold(state) => println!("# hold state {state:?}"),
95
CallUpdate::Notice(text) => println!("# notice {text}"),
96
_ => {}
97
}
98
}
99
});
73
100
let outcome = run_test_call(session, poll_session, options, control).await;
74
101
drain.abort();
75
102
match outcome {
@@ -2,11 +2,14 @@ use std::path::PathBuf;2
use std::time::Duration;2
use std::time::Duration;3
3
4
use calling::audio_io::AUDIO_MODE_ENV;4
use calling::audio_io::AUDIO_MODE_ENV;5
use calling::{AudioMode, CallOptions, CallReport, call_channel, run_test_call};5
use calling::{AudioMode, CallCommand, CallOptions, CallReport, CallState, CallUpdate, call_channel, run_test_call};6
use session::{DEFAULT_ENDPOINT, Session};6
use session::{DEFAULT_ENDPOINT, Session};7
7
8
const HOLD_AFTER_CONNECTED: Duration = Duration::from_secs(12);8
const HOLD_AFTER_CONNECTED: Duration = Duration::from_secs(12);9
const HARD_LIMIT: Duration = Duration::from_secs(20);9
const HARD_LIMIT: Duration = Duration::from_secs(20);10
const HOLD_START: Duration = Duration::from_secs(4);11
const HOLD_LENGTH: Duration = Duration::from_secs(10);12
const AFTER_RESUME: Duration = Duration::from_secs(20);10
13
11
fn print_report(report: &CallReport) {14
fn print_report(report: &CallReport) {12
println!("# ice connected at {:?} ms, peer connected at {:?} ms", report.ice_connected_ms, report.peer_connected_ms);15
println!("# ice connected at {:?} ms, peer connected at {:?} ms", report.ice_connected_ms, report.peer_connected_ms);@@ -42,6 +45,7 @@ async fn main() {42
let session = Session::connect(&endpoint).await.expect("browser");45
let session = Session::connect(&endpoint).await.expect("browser");43
let poll_session = Session::connect(&endpoint).await.expect("browser");46
let poll_session = Session::connect(&endpoint).await.expect("browser");44
let audio = AudioMode::parse(Some(&std::env::var(AUDIO_MODE_ENV).unwrap_or_else(|_| "tone".to_owned())));47
let audio = AudioMode::parse(Some(&std::env::var(AUDIO_MODE_ENV).unwrap_or_else(|_| "tone".to_owned())));48
let hold = std::env::args().any(|argument| argument == "--hold");45
let rounds: usize = std::env::args().skip_while(|argument| argument != "--rounds").nth(1).and_then(|value| value.parse().ok()).unwrap_or(1);49
let rounds: usize = std::env::args().skip_while(|argument| argument != "--rounds").nth(1).and_then(|value| value.parse().ok()).unwrap_or(1);46
for round in 1..=rounds {50
for round in 1..=rounds {47
println!("# round {round} of {rounds}");51
println!("# round {round} of {rounds}");@@ -49,15 +53,16 @@ async fn main() {49
(Some(path), 2..) => Some(path.with_extension(format!("{round}.wav"))),53
(Some(path), 2..) => Some(path.with_extension(format!("{round}.wav"))),50
_ => wav_path.clone(),54
_ => wav_path.clone(),51
};55
};52
test_call(&session, &poll_session, audio, round_wav).await;56
test_call(&session, &poll_session, audio, round_wav, hold).await;53
}57
}54
}58
}55
59
56
async fn test_call(session: &Session, poll_session: &Session, audio: AudioMode, wav_path: Option<PathBuf>) {60
async fn test_call(session: &Session, poll_session: &Session, audio: AudioMode, wav_path: Option<PathBuf>, hold: bool) {61
let connected_for = if hold { HOLD_START + HOLD_LENGTH + AFTER_RESUME } else { HOLD_AFTER_CONNECTED };57
let options = CallOptions {62
let options = CallOptions {58
audio,63
audio,59
hold_after_connected: Some(HOLD_AFTER_CONNECTED),64
hold_after_connected: Some(connected_for),60
hard_limit: Some(HARD_LIMIT),65
hard_limit: Some(connected_for + HARD_LIMIT - HOLD_AFTER_CONNECTED),61
record_remote: true,66
record_remote: true,62
wav_path: wav_path.clone(),67
wav_path: wav_path.clone(),63
sdp_dump_dir: std::env::var("CALLING_SDP_DUMP").ok().map(PathBuf::from),68
sdp_dump_dir: std::env::var("CALLING_SDP_DUMP").ok().map(PathBuf::from),@@ -66,10 +71,32 @@ async fn test_call(session: &Session, poll_session: &Session, audio: AudioMode,66
};71
};67
println!(72
println!(68
"# Test call, audio {:?}, hang up after {:?} connected (hard limit {:?})",73
"# Test call, audio {:?}, hang up after {:?} connected (hard limit {:?})",69
options.audio, HOLD_AFTER_CONNECTED, HARD_LIMIT74
options.audio, options.hold_after_connected, options.hard_limit70
);75
);71
let (mut handle, control) = call_channel();76
let (mut handle, control) = call_channel();72
let drain = tokio::spawn(async move { while handle.updates.recv().await.is_some() {} });77
let commands = handle.commands.clone();78
let drain = tokio::spawn(async move {79
let mut hold_scheduled = !hold;80
while let Some(update) = handle.updates.recv().await {81
match update {82
CallUpdate::State(CallState::Connected { .. }) if !hold_scheduled => {83
hold_scheduled = true;84
let commands = commands.clone();85
tokio::spawn(async move {86
tokio::time::sleep(HOLD_START).await;87
println!("# hold");88
let _ = commands.send(CallCommand::Hold(true));89
tokio::time::sleep(HOLD_LENGTH).await;90
println!("# resume");91
let _ = commands.send(CallCommand::Hold(false));92
});93
}94
CallUpdate::Hold(state) => println!("# hold state {state:?}"),95
CallUpdate::Notice(text) => println!("# notice {text}"),96
_ => {}97
}98
}99
});73
let outcome = run_test_call(session, poll_session, options, control).await;100
let outcome = run_test_call(session, poll_session, options, control).await;74
drain.abort();101
drain.abort();75
match outcome {102
match outcome {@@ -35,7 +35,7 @@ use crate::end::EndKind;
35
35
use crate::engine::{CallEngine, EngineConfig, Inner};
36
36
use crate::error::{Error, Result};
37
37
use crate::health::{CallHealth, HealthCounters, HealthSampler, QualityTracker, TransportDetails, health_from_stats};
38
use crate::hold::{HoldState, INACTIVE, MediaLine, accepted_modalities, is_hold, rewrite_directions};
38
use crate::hold::{HoldState, INACTIVE, MediaLine, accepted_modalities, is_hold, keep_media_running, rewrite_directions};
39
39
use crate::mic_processing::MicSettings;
40
40
use crate::mute::{MuteCommand, MuteEffect};
41
41
use crate::push::CallNotification;
@@ -923,7 +923,10 @@ async fn drive(
923
923
&& let Some(pending) = same_peer.take()
924
924
{
925
925
same_peer_deadline = None;
926
let applied = apply_answer(¤t.peer, &answer.sdp, &pending.signaled, &pending.browser_offer).await;
926
let applied = match pending.change {
927
Change::Hold(_) => apply_hold_answer(¤t.peer, &answer.sdp, &pending.signaled, &pending.browser_offer).await,
928
Change::Camera(_) => apply_answer(¤t.peer, &answer.sdp, &pending.signaled, &pending.browser_offer).await,
929
};
927
930
match applied {
928
931
Ok(()) => {
929
932
if let Some(url) = answer.links.get("mediaAcknowledgement") {
@@ -932,6 +935,7 @@ async fn drive(
932
935
match pending.change {
933
936
Change::Hold(hold) => {
934
937
local_hold = hold;
938
silence_for_hold(local_hold, muted, live.audio.as_ref(), software_audio.as_ref());
935
939
control.send(CallUpdate::Hold(HoldState::from_flags(local_hold, remote_hold)));
936
940
}
937
941
Change::Camera(on) => control.send(CallUpdate::Camera(on)),
@@ -1280,6 +1284,7 @@ async fn drive(
1280
1284
control.send(CallUpdate::Notice(CONSENT_FIRST_NOTICE.into()));
1281
1285
} else {
1282
1286
muted = apply_mute(mute, muted, live.audio.as_ref().expect("audio set above"), software_audio.as_ref(), &remote, control);
1287
silence_for_hold(local_hold, muted, live.audio.as_ref(), software_audio.as_ref());
1283
1288
}
1284
1289
}
1285
1290
Some(CallCommand::DisableAudio) => {
@@ -2070,13 +2075,13 @@ async fn build_same_peer_offer(peer: &PeerConnection, plan: &OfferPlan, layout:
2070
2075
.create_offer(OfferOptions { offer_to_receive_audio: true, offer_to_receive_video: true, ..OfferOptions::default() })
2071
2076
.await
2072
2077
.map_err(|error| Error::Webrtc(error.to_string()))?;
2073
let text = directions_for(layout, hold, camera, &offer.to_string());
2078
let text = directions_for(layout, false, camera, &offer.to_string());
2074
2079
let description = parse_sdp(&text, SdpType::Offer)?;
2075
2080
peer.set_local_description(description)
2076
2081
.await
2077
2082
.map_err(|error| Error::Webrtc(error.to_string()))?;
2078
2083
let mut numbers = random_u32;
2079
let signaled = to_teams_offer(&text, plan, &mut numbers)?;
2084
let signaled = to_teams_offer(&directions_for(layout, hold, camera, &text), plan, &mut numbers)?;
2080
2085
Ok((text, signaled))
2081
2086
}
2082
2087
@@ -2323,6 +2328,16 @@ fn apply_mute(
2323
2328
effect.muted
2324
2329
}
2325
2330
2331
fn silence_for_hold(on_hold: bool, muted: bool, audio: Option<&AudioSetup>, software_audio: Option<&SoftwareAudio>) {
2332
let silent = on_hold || muted;
2333
if let Some(audio) = audio {
2334
audio.track.set_enabled(MuteEffect::for_muted(silent).track_enabled);
2335
}
2336
if let Some(software_audio) = software_audio {
2337
software_audio.set_microphone_muted(silent);
2338
}
2339
}
2340
2326
2341
fn swap_audio_track(peer: &PeerConnection, track: &RtcAudioTrack) -> Result<()> {
2327
2342
let sender = peer
2328
2343
.senders()
@@ -2473,7 +2488,17 @@ fn handle_callback(callback: &TrouterCallback, timeline: &Timeline) -> Result<Ca
2473
2488
2474
2489
async fn apply_answer(peer: &PeerConnection, teams_answer: &str, signaled: &SignaledOffer, browser_offer: &str) -> Result<()> {
2475
2490
let answer = to_browser_answer(teams_answer, signaled, browser_offer)?;
2476
let description = parse_sdp(&answer, SdpType::Answer)?;
2491
set_browser_answer(peer, &answer).await
2492
}
2493
2494
/// libwebrtc does not restart a send stream that an inactive answer stopped, so a hold keeps the streams and only mutes.
2495
async fn apply_hold_answer(peer: &PeerConnection, teams_answer: &str, signaled: &SignaledOffer, browser_offer: &str) -> Result<()> {
2496
let answer = to_browser_answer(teams_answer, signaled, browser_offer)?;
2497
set_browser_answer(peer, &keep_media_running(&answer, browser_offer)).await
2498
}
2499
2500
async fn set_browser_answer(peer: &PeerConnection, answer: &str) -> Result<()> {
2501
let description = parse_sdp(answer, SdpType::Answer)?;
2477
2502
peer.set_remote_description(description)
2478
2503
.await
2479
2504
.map_err(|error| Error::Webrtc(error.to_string()))
@@ -2744,6 +2769,15 @@ mod tests {
2744
2769
assert_eq!(directions_for(Layout::Conference, false, true, BROWSER_OFFER), BROWSER_OFFER);
2745
2770
}
2746
2771
2772
#[test]
2773
fn a_hold_offer_body_is_inactive_on_every_teams_line_with_one_placeholder_candidate() {
2774
let held = directions_for(Layout::Conference, true, false, BROWSER_OFFER);
2775
let mut numbers = || 7;
2776
let signaled = to_teams_offer(&held, &offer_plan(), &mut numbers).unwrap().sdp;
2777
assert_eq!(directions(&signaled), vec!["inactive", "inactive", "inactive"]);
2778
assert_eq!(signaled.matches("a=candidate:").count(), 1);
2779
}
2780
2747
2781
#[test]
2748
2782
fn a_move_into_the_meeting_you_are_already_in_is_ignored() {
2749
2783
let target = |thread: &str| MeetingTarget { thread_id: thread.into(), tenant_id: "t".into(), organizer_id: "o".into(), meeting_data: None };
@@ -35,7 +35,7 @@ use crate::end::EndKind;35
use crate::engine::{CallEngine, EngineConfig, Inner};35
use crate::engine::{CallEngine, EngineConfig, Inner};36
use crate::error::{Error, Result};36
use crate::error::{Error, Result};37
use crate::health::{CallHealth, HealthCounters, HealthSampler, QualityTracker, TransportDetails, health_from_stats};37
use crate::health::{CallHealth, HealthCounters, HealthSampler, QualityTracker, TransportDetails, health_from_stats};38
use crate::hold::{HoldState, INACTIVE, MediaLine, accepted_modalities, is_hold, rewrite_directions};38
use crate::hold::{HoldState, INACTIVE, MediaLine, accepted_modalities, is_hold, keep_media_running, rewrite_directions};39
use crate::mic_processing::MicSettings;39
use crate::mic_processing::MicSettings;40
use crate::mute::{MuteCommand, MuteEffect};40
use crate::mute::{MuteCommand, MuteEffect};41
use crate::push::CallNotification;41
use crate::push::CallNotification;@@ -923,7 +923,10 @@ async fn drive(923
&& let Some(pending) = same_peer.take()923
&& let Some(pending) = same_peer.take()924
{924
{925
same_peer_deadline = None;925
same_peer_deadline = None;926
let applied = apply_answer(¤t.peer, &answer.sdp, &pending.signaled, &pending.browser_offer).await;926
let applied = match pending.change {927
Change::Hold(_) => apply_hold_answer(¤t.peer, &answer.sdp, &pending.signaled, &pending.browser_offer).await,928
Change::Camera(_) => apply_answer(¤t.peer, &answer.sdp, &pending.signaled, &pending.browser_offer).await,929
};927
match applied {930
match applied {928
Ok(()) => {931
Ok(()) => {929
if let Some(url) = answer.links.get("mediaAcknowledgement") {932
if let Some(url) = answer.links.get("mediaAcknowledgement") {@@ -932,6 +935,7 @@ async fn drive(932
match pending.change {935
match pending.change {933
Change::Hold(hold) => {936
Change::Hold(hold) => {934
local_hold = hold;937
local_hold = hold;938
silence_for_hold(local_hold, muted, live.audio.as_ref(), software_audio.as_ref());935
control.send(CallUpdate::Hold(HoldState::from_flags(local_hold, remote_hold)));939
control.send(CallUpdate::Hold(HoldState::from_flags(local_hold, remote_hold)));936
}940
}937
Change::Camera(on) => control.send(CallUpdate::Camera(on)),941
Change::Camera(on) => control.send(CallUpdate::Camera(on)),@@ -1280,6 +1284,7 @@ async fn drive(1280
control.send(CallUpdate::Notice(CONSENT_FIRST_NOTICE.into()));1284
control.send(CallUpdate::Notice(CONSENT_FIRST_NOTICE.into()));1281
} else {1285
} else {1282
muted = apply_mute(mute, muted, live.audio.as_ref().expect("audio set above"), software_audio.as_ref(), &remote, control);1286
muted = apply_mute(mute, muted, live.audio.as_ref().expect("audio set above"), software_audio.as_ref(), &remote, control);1287
silence_for_hold(local_hold, muted, live.audio.as_ref(), software_audio.as_ref());1283
}1288
}1284
}1289
}1285
Some(CallCommand::DisableAudio) => {1290
Some(CallCommand::DisableAudio) => {@@ -2070,13 +2075,13 @@ async fn build_same_peer_offer(peer: &PeerConnection, plan: &OfferPlan, layout:2070
.create_offer(OfferOptions { offer_to_receive_audio: true, offer_to_receive_video: true, ..OfferOptions::default() })2075
.create_offer(OfferOptions { offer_to_receive_audio: true, offer_to_receive_video: true, ..OfferOptions::default() })2071
.await2076
.await2072
.map_err(|error| Error::Webrtc(error.to_string()))?;2077
.map_err(|error| Error::Webrtc(error.to_string()))?;2073
let text = directions_for(layout, hold, camera, &offer.to_string());2078
let text = directions_for(layout, false, camera, &offer.to_string());2074
let description = parse_sdp(&text, SdpType::Offer)?;2079
let description = parse_sdp(&text, SdpType::Offer)?;2075
peer.set_local_description(description)2080
peer.set_local_description(description)2076
.await2081
.await2077
.map_err(|error| Error::Webrtc(error.to_string()))?;2082
.map_err(|error| Error::Webrtc(error.to_string()))?;2078
let mut numbers = random_u32;2083
let mut numbers = random_u32;2079
let signaled = to_teams_offer(&text, plan, &mut numbers)?;2084
let signaled = to_teams_offer(&directions_for(layout, hold, camera, &text), plan, &mut numbers)?;2080
Ok((text, signaled))2085
Ok((text, signaled))2081
}2086
}2082
2087
@@ -2323,6 +2328,16 @@ fn apply_mute(2323
effect.muted2328
effect.muted2324
}2329
}2325
2330
2331
fn silence_for_hold(on_hold: bool, muted: bool, audio: Option<&AudioSetup>, software_audio: Option<&SoftwareAudio>) {2332
let silent = on_hold || muted;2333
if let Some(audio) = audio {2334
audio.track.set_enabled(MuteEffect::for_muted(silent).track_enabled);2335
}2336
if let Some(software_audio) = software_audio {2337
software_audio.set_microphone_muted(silent);2338
}2339
}2340
2326
fn swap_audio_track(peer: &PeerConnection, track: &RtcAudioTrack) -> Result<()> {2341
fn swap_audio_track(peer: &PeerConnection, track: &RtcAudioTrack) -> Result<()> {2327
let sender = peer2342
let sender = peer2328
.senders()2343
.senders()@@ -2473,7 +2488,17 @@ fn handle_callback(callback: &TrouterCallback, timeline: &Timeline) -> Result<Ca2473
2488
2474
async fn apply_answer(peer: &PeerConnection, teams_answer: &str, signaled: &SignaledOffer, browser_offer: &str) -> Result<()> {2489
async fn apply_answer(peer: &PeerConnection, teams_answer: &str, signaled: &SignaledOffer, browser_offer: &str) -> Result<()> {2475
let answer = to_browser_answer(teams_answer, signaled, browser_offer)?;2490
let answer = to_browser_answer(teams_answer, signaled, browser_offer)?;2476
let description = parse_sdp(&answer, SdpType::Answer)?;2491
set_browser_answer(peer, &answer).await2492
}2493
2494
/// libwebrtc does not restart a send stream that an inactive answer stopped, so a hold keeps the streams and only mutes.2495
async fn apply_hold_answer(peer: &PeerConnection, teams_answer: &str, signaled: &SignaledOffer, browser_offer: &str) -> Result<()> {2496
let answer = to_browser_answer(teams_answer, signaled, browser_offer)?;2497
set_browser_answer(peer, &keep_media_running(&answer, browser_offer)).await2498
}2499
2500
async fn set_browser_answer(peer: &PeerConnection, answer: &str) -> Result<()> {2501
let description = parse_sdp(answer, SdpType::Answer)?;2477
peer.set_remote_description(description)2502
peer.set_remote_description(description)2478
.await2503
.await2479
.map_err(|error| Error::Webrtc(error.to_string()))2504
.map_err(|error| Error::Webrtc(error.to_string()))@@ -2744,6 +2769,15 @@ mod tests {2744
assert_eq!(directions_for(Layout::Conference, false, true, BROWSER_OFFER), BROWSER_OFFER);2769
assert_eq!(directions_for(Layout::Conference, false, true, BROWSER_OFFER), BROWSER_OFFER);2745
}2770
}2746
2771
2772
#[test]2773
fn a_hold_offer_body_is_inactive_on_every_teams_line_with_one_placeholder_candidate() {2774
let held = directions_for(Layout::Conference, true, false, BROWSER_OFFER);2775
let mut numbers = || 7;2776
let signaled = to_teams_offer(&held, &offer_plan(), &mut numbers).unwrap().sdp;2777
assert_eq!(directions(&signaled), vec!["inactive", "inactive", "inactive"]);2778
assert_eq!(signaled.matches("a=candidate:").count(), 1);2779
}2780
2747
#[test]2781
#[test]2748
fn a_move_into_the_meeting_you_are_already_in_is_ignored() {2782
fn a_move_into_the_meeting_you_are_already_in_is_ignored() {2749
let target = |thread: &str| MeetingTarget { thread_id: thread.into(), tenant_id: "t".into(), organizer_id: "o".into(), meeting_data: None };2783
let target = |thread: &str| MeetingTarget { thread_id: thread.into(), tenant_id: "t".into(), organizer_id: "o".into(), meeting_data: None };@@ -1,3 +1,5 @@
1
use std::collections::HashMap;
2
1
3
use crate::error::Result;
2
4
use crate::sdp::parse;
3
5
@@ -68,6 +70,27 @@ pub fn rewrite_directions(sdp: &str, pick: impl Fn(MediaLine<'_>) -> Option<&'st
68
70
lines.join(newline)
69
71
}
70
72
73
fn mirrored(direction: &str) -> &'static str {
74
match direction {
75
"sendonly" => "recvonly",
76
"recvonly" => "sendonly",
77
"inactive" => INACTIVE,
78
_ => "sendrecv",
79
}
80
}
81
82
pub fn keep_media_running(browser_answer: &str, browser_offer: &str) -> String {
83
let offer_lines: Vec<String> = browser_offer.split('\n').map(|line| line.trim_end_matches('\r').to_owned()).collect();
84
let offered: HashMap<String, &'static str> = sections(&offer_lines)
85
.into_iter()
86
.filter_map(|section| {
87
let direction = offer_lines[section.direction_line?].strip_prefix("a=")?;
88
Some((section.mid, mirrored(direction)))
89
})
90
.collect();
91
rewrite_directions(browser_answer, |line| offered.get(line.mid).copied())
92
}
93
71
94
pub fn all_inactive(sdp: &str) -> String {
72
95
rewrite_directions(sdp, |_| Some(INACTIVE))
73
96
}
@@ -148,6 +171,14 @@ mod tests {
148
171
assert_eq!(directions(&held), vec!["inactive", "inactive", "inactive"]);
149
172
}
150
173
174
#[test]
175
fn a_hold_answer_mirrors_our_offer_so_nothing_stops_locally() {
176
let answer = all_inactive(&OFFER.replace("a=setup:actpass", "a=setup:passive"));
177
let kept = keep_media_running(&answer, OFFER);
178
assert_eq!(directions(&kept), vec!["sendrecv", "sendrecv", "sendonly"]);
179
assert_eq!(kept.lines().count(), answer.lines().count());
180
}
181
151
182
#[test]
152
183
fn a_hold_is_every_audio_and_video_line_inactive() {
153
184
assert!(is_hold(&all_inactive(OFFER)).unwrap());
@@ -1,3 +1,5 @@1
use std::collections::HashMap;2
1
use crate::error::Result;3
use crate::error::Result;2
use crate::sdp::parse;4
use crate::sdp::parse;3
5
@@ -68,6 +70,27 @@ pub fn rewrite_directions(sdp: &str, pick: impl Fn(MediaLine<'_>) -> Option<&'st68
lines.join(newline)70
lines.join(newline)69
}71
}70
72
73
fn mirrored(direction: &str) -> &'static str {74
match direction {75
"sendonly" => "recvonly",76
"recvonly" => "sendonly",77
"inactive" => INACTIVE,78
_ => "sendrecv",79
}80
}81
82
pub fn keep_media_running(browser_answer: &str, browser_offer: &str) -> String {83
let offer_lines: Vec<String> = browser_offer.split('\n').map(|line| line.trim_end_matches('\r').to_owned()).collect();84
let offered: HashMap<String, &'static str> = sections(&offer_lines)85
.into_iter()86
.filter_map(|section| {87
let direction = offer_lines[section.direction_line?].strip_prefix("a=")?;88
Some((section.mid, mirrored(direction)))89
})90
.collect();91
rewrite_directions(browser_answer, |line| offered.get(line.mid).copied())92
}93
71
pub fn all_inactive(sdp: &str) -> String {94
pub fn all_inactive(sdp: &str) -> String {72
rewrite_directions(sdp, |_| Some(INACTIVE))95
rewrite_directions(sdp, |_| Some(INACTIVE))73
}96
}@@ -148,6 +171,14 @@ mod tests {148
assert_eq!(directions(&held), vec!["inactive", "inactive", "inactive"]);171
assert_eq!(directions(&held), vec!["inactive", "inactive", "inactive"]);149
}172
}150
173
174
#[test]175
fn a_hold_answer_mirrors_our_offer_so_nothing_stops_locally() {176
let answer = all_inactive(&OFFER.replace("a=setup:actpass", "a=setup:passive"));177
let kept = keep_media_running(&answer, OFFER);178
assert_eq!(directions(&kept), vec!["sendrecv", "sendrecv", "sendonly"]);179
assert_eq!(kept.lines().count(), answer.lines().count());180
}181
151
#[test]182
#[test]152
fn a_hold_is_every_audio_and_video_line_inactive() {183
fn a_hold_is_every_audio_and_video_line_inactive() {153
assert!(is_hold(&all_inactive(OFFER)).unwrap());184
assert!(is_hold(&all_inactive(OFFER)).unwrap());@@ -436,7 +436,7 @@ fn signal_rtp_line(
436
436
for attribute in &source.attributes {
437
437
let value = attribute.value.as_deref().unwrap_or_default();
438
438
match attribute.name.as_str() {
439
"ssrc" | "ssrc-group" | "rid" | "simulcast" | "rtcp-xr" | "rtcp-fb" => {}
439
"ssrc" | "ssrc-group" | "rid" | "simulcast" | "rtcp-xr" | "rtcp-fb" | "candidate" | "end-of-candidates" => {}
440
440
"rtpmap" => attributes.push(Attribute::new("rtpmap", signal_rtpmap(value))),
441
441
"fmtp" => {
442
442
let payload = value.split(' ').next().unwrap_or_default();
@@ -1070,6 +1070,17 @@ mod tests {
1070
1070
assert_eq!(offer.lines, vec![SignaledLine { browser_mids: vec!["0".into()], role: LineRole::MainAudio }]);
1071
1071
}
1072
1072
1073
#[test]
1074
fn a_renegotiation_signals_only_the_placeholder_candidate() {
1075
let gathered = AUDIO_ONLY_OFFER.replace(
1076
"a=mid:0\r\n",
1077
"a=mid:0\r\na=candidate:1 1 udp 2121998079 192.0.2.1 45325 typ host generation 0 network-id 1\r\na=candidate:2 1 tcp 1518018303 2001:db8::1 47585 typ host tcptype passive generation 0 network-id 2\r\na=end-of-candidates\r\n",
1078
);
1079
let text = to_teams_offer(&gathered, &OfferPlan::default(), &mut counter()).unwrap().sdp;
1080
let candidates: Vec<&str> = text.lines().filter(|line| line.starts_with("a=candidate:") || line.starts_with("a=end-of-candidates")).collect();
1081
assert_eq!(candidates, vec!["a=candidate:1755259772 1 UDP 2122197247 10.10.10.10 1234 typ host"]);
1082
}
1083
1073
1084
#[test]
1074
1085
fn answer_candidates_lose_teams_extensions() {
1075
1086
assert_eq!(
@@ -436,7 +436,7 @@ fn signal_rtp_line(436
for attribute in &source.attributes {436
for attribute in &source.attributes {437
let value = attribute.value.as_deref().unwrap_or_default();437
let value = attribute.value.as_deref().unwrap_or_default();438
match attribute.name.as_str() {438
match attribute.name.as_str() {439
"ssrc" | "ssrc-group" | "rid" | "simulcast" | "rtcp-xr" | "rtcp-fb" => {}439
"ssrc" | "ssrc-group" | "rid" | "simulcast" | "rtcp-xr" | "rtcp-fb" | "candidate" | "end-of-candidates" => {}440
"rtpmap" => attributes.push(Attribute::new("rtpmap", signal_rtpmap(value))),440
"rtpmap" => attributes.push(Attribute::new("rtpmap", signal_rtpmap(value))),441
"fmtp" => {441
"fmtp" => {442
let payload = value.split(' ').next().unwrap_or_default();442
let payload = value.split(' ').next().unwrap_or_default();@@ -1070,6 +1070,17 @@ mod tests {1070
assert_eq!(offer.lines, vec![SignaledLine { browser_mids: vec!["0".into()], role: LineRole::MainAudio }]);1070
assert_eq!(offer.lines, vec![SignaledLine { browser_mids: vec!["0".into()], role: LineRole::MainAudio }]);1071
}1071
}1072
1072
1073
#[test]1074
fn a_renegotiation_signals_only_the_placeholder_candidate() {1075
let gathered = AUDIO_ONLY_OFFER.replace(1076
"a=mid:0\r\n",1077
"a=mid:0\r\na=candidate:1 1 udp 2121998079 192.0.2.1 45325 typ host generation 0 network-id 1\r\na=candidate:2 1 tcp 1518018303 2001:db8::1 47585 typ host tcptype passive generation 0 network-id 2\r\na=end-of-candidates\r\n",1078
);1079
let text = to_teams_offer(&gathered, &OfferPlan::default(), &mut counter()).unwrap().sdp;1080
let candidates: Vec<&str> = text.lines().filter(|line| line.starts_with("a=candidate:") || line.starts_with("a=end-of-candidates")).collect();1081
assert_eq!(candidates, vec!["a=candidate:1755259772 1 UDP 2122197247 10.10.10.10 1234 typ host"]);1082
}1083
1073
#[test]1084
#[test]1074
fn answer_candidates_lose_teams_extensions() {1085
fn answer_candidates_lose_teams_extensions() {1075
assert_eq!(1086
assert_eq!(