[fix](trx-frontend-http): fix decode SSE status detection

Replace HEAD probe with EventSource readyState check to properly
detect 404 vs connection drop. HEAD requests to SSE endpoints may
not behave reliably across all setups.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
2026-02-08 22:57:19 +01:00
parent dba2f0a9fb
commit 2feecbfe4f
@@ -1133,37 +1133,33 @@ function updateDecodeStatus(text) {
} }
function connectDecode() { function connectDecode() {
if (decodeSource) { decodeSource.close(); } if (decodeSource) { decodeSource.close(); }
// Probe first to distinguish 404 from real SSE errors decodeSource = new EventSource("/decode");
fetch("/decode", { method: "HEAD" }).then((r) => { decodeSource.onopen = () => {
if (r.status === 404) { decodeConnected = true;
updateDecodeStatus("Decode not available (audio disabled?)"); updateDecodeStatus("Connected, listening for packets");
setTimeout(connectDecode, 10000); };
return; decodeSource.onmessage = (evt) => {
try {
const msg = JSON.parse(evt.data);
if (msg.type === "aprs" && window.onServerAprs) window.onServerAprs(msg);
if (msg.type === "cw" && window.onServerCw) window.onServerCw(msg);
} catch (e) {
// ignore parse errors
} }
decodeSource = new EventSource("/decode"); };
decodeSource.onopen = () => { decodeSource.onerror = () => {
decodeConnected = true; // readyState CLOSED (2) = server rejected (404/error), CONNECTING (0) = temporary drop
updateDecodeStatus("Connected, listening for packets"); const wasClosed = decodeSource.readyState === 2;
}; decodeSource.close();
decodeSource.onmessage = (evt) => { decodeConnected = false;
try { if (wasClosed) {
const msg = JSON.parse(evt.data); updateDecodeStatus("Decode not available (check client audio config)");
if (msg.type === "aprs" && window.onServerAprs) window.onServerAprs(msg); setTimeout(connectDecode, 10000);
if (msg.type === "cw" && window.onServerCw) window.onServerCw(msg); } else {
} catch (e) {
// ignore parse errors
}
};
decodeSource.onerror = () => {
decodeSource.close();
decodeConnected = false;
updateDecodeStatus("Decode disconnected, retrying…"); updateDecodeStatus("Decode disconnected, retrying…");
setTimeout(connectDecode, 5000); setTimeout(connectDecode, 5000);
}; }
}).catch(() => { };
updateDecodeStatus("Decode endpoint unreachable");
setTimeout(connectDecode, 5000);
});
} }
connectDecode(); connectDecode();