[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 <noreply@anthropic.com> Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
@@ -3183,7 +3183,10 @@ function connect() {
|
|||||||
clearInterval(esHeartbeat);
|
clearInterval(esHeartbeat);
|
||||||
}
|
}
|
||||||
pollFreshSnapshot();
|
pollFreshSnapshot();
|
||||||
es = new EventSource("/events");
|
const eventsUrl = lastActiveRigId
|
||||||
|
? `/events?rig_id=${encodeURIComponent(lastActiveRigId)}`
|
||||||
|
: "/events";
|
||||||
|
es = new EventSource(eventsUrl);
|
||||||
lastEventAt = Date.now();
|
lastEventAt = Date.now();
|
||||||
es.onopen = () => {
|
es.onopen = () => {
|
||||||
setConnLostOverlay(false);
|
setConnLostOverlay(false);
|
||||||
|
|||||||
@@ -323,9 +323,15 @@ fn decode_history_retention_min_from_context(context: &FrontendRuntimeContext) -
|
|||||||
.unwrap_or(default_minutes)
|
.unwrap_or(default_minutes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
pub struct EventsQuery {
|
||||||
|
pub rig_id: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/events")]
|
#[get("/events")]
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn events(
|
pub async fn events(
|
||||||
|
query: web::Query<EventsQuery>,
|
||||||
state: web::Data<watch::Receiver<RigState>>,
|
state: web::Data<watch::Receiver<RigState>>,
|
||||||
clients: web::Data<Arc<AtomicUsize>>,
|
clients: web::Data<Arc<AtomicUsize>>,
|
||||||
context: web::Data<Arc<FrontendRuntimeContext>>,
|
context: web::Data<Arc<FrontendRuntimeContext>>,
|
||||||
@@ -342,13 +348,20 @@ pub async fn events(
|
|||||||
let session_id = Uuid::new_v4();
|
let session_id = Uuid::new_v4();
|
||||||
scheduler_control.register_session(session_id);
|
scheduler_control.register_session(session_id);
|
||||||
|
|
||||||
// Seed the primary channel for the currently-selected rig (no-op if
|
// Use the client-requested rig_id if provided, otherwise fall back to
|
||||||
// already initialised or if no rig is selected yet).
|
// the global default. This allows each tab to reconnect SSE for the
|
||||||
let active_rig_id = context
|
// rig it has selected without mutating global state.
|
||||||
.remote_active_rig_id
|
let active_rig_id = query
|
||||||
.lock()
|
.rig_id
|
||||||
.ok()
|
.clone()
|
||||||
.and_then(|g| g.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,
|
// Subscribe to the per-rig watch channel for this session's rig,
|
||||||
// falling back to the global state watch when unavailable.
|
// falling back to the global state watch when unavailable.
|
||||||
|
|||||||
Reference in New Issue
Block a user