[fix](trx-client): update per-rig state channel on command response

send_command only updated the global state_tx watch channel, but SSE
sessions subscribe to per-rig rig_states channels. Per-rig channels were
only updated during the poll cycle (default 750ms). Now send_command also
pushes state to the per-rig channel immediately, eliminating up to 750ms
of latency for confirmed frequency/mode/state changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
2026-03-22 09:09:59 +01:00
parent 3ad5f7a3b7
commit 4ad5bf863d
+20 -1
View File
@@ -344,7 +344,26 @@ async fn send_command(
if resp.success {
if let Some(snapshot) = resp.state {
let _ = state_tx.send(RigState::from_snapshot(snapshot.clone()));
let new_state = RigState::from_snapshot(snapshot.clone());
let _ = state_tx.send(new_state.clone());
// Also update the per-rig watch channel so SSE sessions
// subscribed to a specific rig see the change immediately
// instead of waiting for the next poll cycle.
let rig_id = envelope.rig_id.as_deref();
if let Some(rid) = rig_id {
if let Ok(map) = config.rig_states.read() {
if let Some(tx) = map.get(rid) {
tx.send_if_modified(|old| {
if *old == new_state {
false
} else {
*old = new_state.clone();
true
}
});
}
}
}
return Ok(snapshot);
}
return Err(RigError::communication("missing snapshot"));