From c3321729000e0dcbdfeb8c115e1f2e4fb4c68ec2 Mon Sep 17 00:00:00 2001 From: Stan Grams Date: Sun, 22 Mar 2026 00:04:36 +0100 Subject: [PATCH] [fix](trx-frontend-http): pass rig_id to SSE endpoint on reconnect After select_rig stopped mutating the global remote_active_rig_id for session-aware clients, SSE reconnects would fall back to the old global default instead of the newly selected rig. Now connect() passes lastActiveRigId as a rig_id query param to /events, and the server prefers it over the global default when present. Co-Authored-By: Claude Opus 4.6 Signed-off-by: Stan Grams --- .../trx-frontend-http/assets/web/app.js | 5 +++- .../trx-frontend/trx-frontend-http/src/api.rs | 27 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/trx-client/trx-frontend/trx-frontend-http/assets/web/app.js b/src/trx-client/trx-frontend/trx-frontend-http/assets/web/app.js index 9a33c7f..7789f9f 100644 --- a/src/trx-client/trx-frontend/trx-frontend-http/assets/web/app.js +++ b/src/trx-client/trx-frontend/trx-frontend-http/assets/web/app.js @@ -3183,7 +3183,10 @@ function connect() { clearInterval(esHeartbeat); } pollFreshSnapshot(); - es = new EventSource("/events"); + const eventsUrl = lastActiveRigId + ? `/events?rig_id=${encodeURIComponent(lastActiveRigId)}` + : "/events"; + es = new EventSource(eventsUrl); lastEventAt = Date.now(); es.onopen = () => { setConnLostOverlay(false); diff --git a/src/trx-client/trx-frontend/trx-frontend-http/src/api.rs b/src/trx-client/trx-frontend/trx-frontend-http/src/api.rs index 3e3f99e..2538364 100644 --- a/src/trx-client/trx-frontend/trx-frontend-http/src/api.rs +++ b/src/trx-client/trx-frontend/trx-frontend-http/src/api.rs @@ -323,9 +323,15 @@ fn decode_history_retention_min_from_context(context: &FrontendRuntimeContext) - .unwrap_or(default_minutes) } +#[derive(serde::Deserialize)] +pub struct EventsQuery { + pub rig_id: Option, +} + #[get("/events")] #[allow(clippy::too_many_arguments)] pub async fn events( + query: web::Query, state: web::Data>, clients: web::Data>, context: web::Data>, @@ -342,13 +348,20 @@ pub async fn events( let session_id = Uuid::new_v4(); scheduler_control.register_session(session_id); - // Seed the primary channel for the currently-selected rig (no-op if - // already initialised or if no rig is selected yet). - let active_rig_id = context - .remote_active_rig_id - .lock() - .ok() - .and_then(|g| g.clone()); + // Use the client-requested rig_id if provided, otherwise fall back to + // the global default. This allows each tab to reconnect SSE for the + // rig it has selected without mutating global state. + let active_rig_id = query + .rig_id + .clone() + .filter(|s| !s.is_empty()) + .or_else(|| { + context + .remote_active_rig_id + .lock() + .ok() + .and_then(|g| g.clone()) + }); // Subscribe to the per-rig watch channel for this session's rig, // falling back to the global state watch when unavailable.