fix(client): keep the live voice session visible and stop orphaned microphones
Switching from room A to room B replaced the voice state with a joining state while the microphone was still capturing in A, and a deleted room left the capture pipeline running with no visible state. A pending join is now stored separately, so the live session stays shown as connected until the server acknowledges the new room or refuses it. The capture pipeline is stopped whenever it no longer belongs to the current voice target, whatever a pending join is waiting for.
This commit is contained in:
parent
7d488faf59
commit
bf485720f5
4 changed files with 90 additions and 46 deletions
|
|
@ -453,6 +453,9 @@ fn chat_handle(ui: &mut UiState, net: &NetHandle, event: NetEvent) {
|
|||
}
|
||||
if kind == "voice" {
|
||||
ui.voice_target = Some(channel_id.clone());
|
||||
if ui.pending_voice_join.as_deref() == Some(channel_id.as_str()) {
|
||||
ui.pending_voice_join = None;
|
||||
}
|
||||
// A newly acknowledged join is also an explicit retry after an audio error.
|
||||
if matches!(ui.voice, VoiceUiState::Error(_)) {
|
||||
ui.voice = VoiceUiState::Off;
|
||||
|
|
@ -930,10 +933,16 @@ pub fn sync_voice_audio(state: &mut AppState) {
|
|||
return;
|
||||
}
|
||||
let active_voice = state.ui.voice_target.clone();
|
||||
if pipeline_should_stop(
|
||||
active_voice.as_deref(),
|
||||
state.audio.as_ref().and(state.voice_channel.as_deref()),
|
||||
) {
|
||||
stop_voice(state);
|
||||
}
|
||||
match active_voice {
|
||||
Some(id) => start_voice(state, &id),
|
||||
// A pending join has no target until the server acknowledges it.
|
||||
None if matches!(state.ui.voice, VoiceUiState::Joining { .. }) => {}
|
||||
// No target (room deleted, revoked, left): the capture pipeline must not outlive it,
|
||||
// whatever a pending join is waiting for.
|
||||
None => stop_voice(state),
|
||||
}
|
||||
}
|
||||
|
|
@ -1018,3 +1027,32 @@ fn log_audio_stats(state: &AppState) {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A live capture pipeline must belong to the room the client is currently targeting. When the
|
||||
/// target disappears (room deleted, access revoked) or moves elsewhere, the microphone stops
|
||||
/// immediately, independent of what a pending join is waiting for.
|
||||
fn pipeline_should_stop(target: Option<&str>, live_channel: Option<&str>) -> bool {
|
||||
live_channel.is_some() && live_channel != target
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod voice_pipeline_tests {
|
||||
use super::pipeline_should_stop;
|
||||
|
||||
#[test]
|
||||
fn deleted_room_stops_the_microphone() {
|
||||
assert!(pipeline_should_stop(None, Some("a")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moving_to_another_room_stops_the_old_pipeline() {
|
||||
assert!(pipeline_should_stop(Some("b"), Some("a")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn matching_room_or_no_pipeline_is_left_alone() {
|
||||
assert!(!pipeline_should_stop(Some("a"), Some("a")));
|
||||
assert!(!pipeline_should_stop(None, None));
|
||||
assert!(!pipeline_should_stop(Some("a"), None));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue