fix(app): moving to another voice channel no longer ends the new session
- Same-server moves point the existing songbird connection at the new channel and replace its handlers; removing and rejoining at once let the late gateway "left" update cancel the new join. - A driver disconnect without a reason (our own leave or move) is ignored, and a disconnect only ends the session its handler belongs to, so an old connection's late event cannot end a newer one. - Live test: move to a second voice channel and back; the session survives both, only the two moves end one, and the speaker is still heard afterwards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
//!
|
||||
//! JARVIS_LIVE_DISCORD=1 JARVIS_LIVE_BOT_TOKEN=... JARVIS_LIVE_SPEAKER_TOKEN=... \
|
||||
//! JARVIS_LIVE_GUILD=<server id> JARVIS_LIVE_VOICE_CHANNEL=<voice channel id> \
|
||||
//! JARVIS_LIVE_VOICE_CHANNEL_2=<another voice channel of that server> \
|
||||
//! JARVIS_VOICE_PYTHON=<worker venv python> JARVIS_MELO_PYTHON=<MeloTTS venv python> \
|
||||
//! cargo test --release --test live_discord -- --nocapture
|
||||
//!
|
||||
@@ -134,6 +135,7 @@ async fn discord_voice_core_on_real_discord() {
|
||||
}
|
||||
let guild: u64 = env("JARVIS_LIVE_GUILD").parse().unwrap();
|
||||
let voice: u64 = env("JARVIS_LIVE_VOICE_CHANNEL").parse().unwrap();
|
||||
let voice2: u64 = env("JARVIS_LIVE_VOICE_CHANNEL_2").parse().unwrap();
|
||||
let bot_token = env("JARVIS_LIVE_BOT_TOKEN");
|
||||
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let samples = root.join("../scripts/m0/assets/ko_samples");
|
||||
@@ -151,9 +153,9 @@ async fn discord_voice_core_on_real_discord() {
|
||||
until("guild in cache", 10_000, || s_cache.guild(GuildId::new(guild)).is_some()).await;
|
||||
{
|
||||
let g = s_cache.guild(GuildId::new(guild)).unwrap();
|
||||
let people = g.voice_states.values().filter(|v| v.channel_id.map(|c| c.get()) == Some(voice)
|
||||
let people = g.voice_states.values().filter(|v| v.channel_id.is_some_and(|c| c.get() == voice || c.get() == voice2)
|
||||
&& !s_cache.user(v.user_id).map(|u| u.bot).unwrap_or(false)).count();
|
||||
assert_eq!(people, 0, "refusing to test: people are in the voice channel");
|
||||
assert_eq!(people, 0, "refusing to test: people are in the voice channels");
|
||||
for id in [speaker_id, jarvis_app_id] {
|
||||
assert!(g.voice_states.get(&UserId::new(id)).and_then(|v| v.channel_id).is_none(),
|
||||
"refusing to test: bot {id} is in a voice channel");
|
||||
@@ -331,7 +333,22 @@ async fn discord_voice_core_on_real_discord() {
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
assert!(!events.lock().unwrap().iter().any(|e| matches!(e, CoreEvent::Chat(c) if c.content == reply)));
|
||||
|
||||
// 6. Group changes: every join and leave changes the DAVE (MLS) group, and songbird has an open
|
||||
// 6. Moving to another channel and back: the old connection's shutdown must not end the new one.
|
||||
for (to, what) in [(voice2, "the second channel"), (voice, "the first channel")] {
|
||||
core.join(to).await.expect("move");
|
||||
tokio::time::sleep(Duration::from_secs(3)).await;
|
||||
assert_eq!(core.voice_channel_id(), Some(to), "session lost after moving to {what}");
|
||||
let in_channel = s_cache.guild(GuildId::new(guild))
|
||||
.and_then(|g| g.voice_states.get(&UserId::new(jarvis)).and_then(|v| v.channel_id)).map(|c| c.get());
|
||||
assert_eq!(in_channel, Some(to), "Jarvis is not in {what} on Discord");
|
||||
}
|
||||
let moves: Vec<String> = events.lock().unwrap().iter().filter_map(|e| match e {
|
||||
CoreEvent::Left { reason, .. } => Some(reason.clone()),
|
||||
_ => None,
|
||||
}).collect();
|
||||
assert_eq!(moves, ["moved", "moved"], "only the two moves end a session");
|
||||
|
||||
// 7. Group changes: every join and leave changes the DAVE (MLS) group, and songbird has an open
|
||||
// report of receive stalling after one (issue #310). The speaker leaves and comes back three
|
||||
// times and must still be heard each time, under its new SSRC.
|
||||
let wav = std::fs::read(samples.join("ko_03.wav")).unwrap();
|
||||
@@ -362,7 +379,7 @@ async fn discord_voice_core_on_real_discord() {
|
||||
report.insert("rejoins".into(), Value::from(rejoins.clone()));
|
||||
assert!(rejoins.iter().all(|r| r["cer"].as_f64().unwrap() < 0.15), "not heard after a rejoin: {rejoins:?}");
|
||||
|
||||
// 7. Leaving.
|
||||
// 8. Leaving.
|
||||
assert!(core.leave("command").await);
|
||||
until("Jarvis to leave", 10_000, || {
|
||||
s_cache.guild(GuildId::new(guild)).and_then(|g| g.voice_states.get(&UserId::new(jarvis)).and_then(|v| v.channel_id)).is_none()
|
||||
|
||||
Reference in New Issue
Block a user