fix(audio,voice,log): six P0 issues from Korean Windows test

1. Voice Bar 'Leave voice' button removed entirely. TeamSpeak users
   are always in some channel; Discord/Mumble-style leave is the
   wrong model. To stop being heard / hearing, mute mic / speaker.
   To physically move, tap a different channel. The voiceLeave
   bridge call + _onLeaveVoice stay as dead code for now (marked
   unused) so existing tests/integrations don't break.

2. voice_join now confirms the move actually applied server-side
   by polling the snapshot for up to 1.5 s and matching our own
   client's channel against the requested one. If the server
   rejected the move (no permission, wrong password, channel
   full), voice_join rolls the selector back to in_channel=false
   and returns Err so the UI surfaces the failure instead of
   showing a fake 'joined' state.

3. ServerSnapshot + BridgeSnapshot gain own_client_id so the UI
   can identify our row without name-matching. find_own_in reads
   it directly.

4. set_self_muted now also clamps the TransmitModeSelector's
   hard_mute when input is muted server-side. Without this, the
   Opus encoder kept producing frames after setInputMuted(true),
   tsclientlib refused each one with 'Sending audio while muted',
   and the log grew to 200 MB on the Korean host.

5. tsclientlib WARN spam suppressed via tracing filter
   (tsclientlib=error). Belt-and-braces on top of fix 4.

6. Log file is now rotated at every launch (not just when >4 MiB).
   Two generations kept: chanora.log.1 (previous) and
   chanora.log.2 (the one before). The bug that produced 200 MB
   files was a chatty subsystem flooding a single session; the
   per-launch rotate keeps disk use bounded by what one session
   can produce in its lifetime.

Bonus Windows fix (separate from the six but found in the same
log): the Raw Input + Hook backends now signal readiness BEFORE
blocking on GetMessageW. Previously init_tx.send was called after
the loop returned (i.e. on WM_QUIT, which never happens during
arming), so the main thread's 2 s readiness probe always timed
out and the backend reported L0Focused even when registration
succeeded. Both run_raw_input_loop and run_hook_loop now take an
init_tx parameter and call report!(true) right after a successful
registration, and report!(false) on every early-fail return.

cargo check --workspace: clean.
cargo test --workspace --lib: 80 passed / 0 failed / 1 ignored.
flutter analyze: clean (6 pre-existing Radio.groupValue infos).
This commit is contained in:
EdisonJwa
2026-05-16 01:52:47 +08:00
parent bb3c82e2d5
commit 181b3368d4
10 changed files with 180 additions and 35 deletions
+70
View File
@@ -785,6 +785,18 @@ impl ChanoraSession {
audio.set_output_muted(muted);
}
}
// When server-side input mute is engaged we must ALSO stop
// producing outbound voice frames locally — otherwise the
// Opus encoder happily writes packets, the protocol layer
// hands them to tsclientlib, tsclientlib refuses them
// because its own ClientMuted flag is set, and logs
// "Sending audio while muted" once per 20 ms frame. That
// flooded the log to 200 MB on the Korean test host.
// Clamp the transmit-mode selector's hard_mute input so
// the gate goes false too.
if let Some(muted) = input {
self.voice_selector.set_hard_mute(muted);
}
Ok(())
}
@@ -855,13 +867,69 @@ impl ChanoraSession {
channel_id: u64,
password: Option<String>,
) -> Result<(), CoreError> {
// 1. Send the move command. This returns Ok even when the
// server later rejects it with a permission error,
// because the rejection arrives as an asynchronous
// server event the adapter doesn't currently surface.
self.move_to_channel(channel_id, password).await?;
// 2. Bring the audio engine up.
self.ensure_audio_running().await?;
// 3. Verify we are actually in the requested channel by
// polling the snapshot for up to 1.5 s. The TS3 server
// typically broadcasts the channel-update within
// ~50200 ms after the move; if we never see ourselves
// move (no-permission, wrong password, channel full,
// etc.) we surface the failure to the caller so the
// Voice Bar doesn't lie about our membership state.
let deadline = std::time::Instant::now() + std::time::Duration::from_millis(1500);
let confirmed = loop {
if let Ok(snap) = self.snapshot().await {
if let Some((my_id, my_channel)) = self.find_own_in(&snap).await {
if my_channel == channel_id {
info!(
target: "chanora_core",
client_id = my_id,
channel_id,
"voice_join confirmed by snapshot"
);
break true;
}
}
}
if std::time::Instant::now() >= deadline {
break false;
}
tokio::time::sleep(std::time::Duration::from_millis(80)).await;
};
if !confirmed {
// The move did not take effect server-side. Roll
// back the local selector so the UI doesn't display
// a fake "joined" state.
self.voice_selector.set_in_channel(false);
self.emit_voice_state(false).await;
return Err(CoreError::Protocol(
chanora_protocol::ProtocolError::Backend(
"channel move rejected by server (no permission, wrong password, or channel full)".to_string(),
),
));
}
self.voice_selector.set_in_channel(true);
self.emit_voice_state(true).await;
Ok(())
}
/// Find our own client in a snapshot and return `(client_id,
/// channel_id)`. Used by `voice_join` to confirm the server
/// actually applied a channel move.
async fn find_own_in(
&self,
snap: &chanora_protocol::ServerSnapshot,
) -> Option<(u64, u64)> {
let own_id = snap.own_client_id;
let me = snap.clients.iter().find(|c| c.id.0 == own_id)?;
Some((me.id.0, me.channel.0))
}
/// Leave the current voice channel (SDD-094). Marks the
/// selector as out-of-channel (which clamps `transmit_active`
/// to false), tears down the audio engine, and emits
@@ -1472,6 +1540,7 @@ mod tests {
channel: chanora_protocol::ChannelId(1),
name: "u".into(),
}],
own_client_id: 10,
};
let mut b = a.clone();
// User moves from channel 1 → 2. Counts unchanged.
@@ -1505,6 +1574,7 @@ mod tests {
},
],
clients: vec![],
own_client_id: 0,
};
let mut b = a.clone();
b.channels.reverse();