[fix](trx-frontend-http): show decode SSE connection status
The decode EventSource silently retried on 404 leaving the status stuck on "Waiting for server decode". Probe /decode first to distinguish 404 (audio disabled) from real SSE errors and update the APRS/CW status text accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
@@ -1125,24 +1125,45 @@ document.getElementById("copyright-year").textContent = new Date().getFullYear()
|
|||||||
// --- Server-side decode SSE ---
|
// --- Server-side decode SSE ---
|
||||||
let decodeSource = null;
|
let decodeSource = null;
|
||||||
let decodeConnected = false;
|
let decodeConnected = false;
|
||||||
|
function updateDecodeStatus(text) {
|
||||||
|
const aprs = document.getElementById("aprs-status");
|
||||||
|
const cw = document.getElementById("cw-status");
|
||||||
|
if (aprs && aprs.textContent !== "Receiving") aprs.textContent = text;
|
||||||
|
if (cw && cw.textContent !== "Receiving") cw.textContent = text;
|
||||||
|
}
|
||||||
function connectDecode() {
|
function connectDecode() {
|
||||||
if (decodeSource) { decodeSource.close(); }
|
if (decodeSource) { decodeSource.close(); }
|
||||||
decodeSource = new EventSource("/decode");
|
// Probe first to distinguish 404 from real SSE errors
|
||||||
decodeSource.onopen = () => { decodeConnected = true; };
|
fetch("/decode", { method: "HEAD" }).then((r) => {
|
||||||
decodeSource.onmessage = (evt) => {
|
if (r.status === 404) {
|
||||||
try {
|
updateDecodeStatus("Decode not available (audio disabled?)");
|
||||||
const msg = JSON.parse(evt.data);
|
setTimeout(connectDecode, 10000);
|
||||||
if (msg.type === "aprs" && window.onServerAprs) window.onServerAprs(msg);
|
return;
|
||||||
if (msg.type === "cw" && window.onServerCw) window.onServerCw(msg);
|
|
||||||
} catch (e) {
|
|
||||||
// ignore parse errors
|
|
||||||
}
|
}
|
||||||
};
|
decodeSource = new EventSource("/decode");
|
||||||
decodeSource.onerror = () => {
|
decodeSource.onopen = () => {
|
||||||
decodeSource.close();
|
decodeConnected = true;
|
||||||
decodeConnected = false;
|
updateDecodeStatus("Connected, listening for packets");
|
||||||
|
};
|
||||||
|
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.onerror = () => {
|
||||||
|
decodeSource.close();
|
||||||
|
decodeConnected = false;
|
||||||
|
updateDecodeStatus("Decode disconnected, retrying…");
|
||||||
|
setTimeout(connectDecode, 5000);
|
||||||
|
};
|
||||||
|
}).catch(() => {
|
||||||
|
updateDecodeStatus("Decode endpoint unreachable");
|
||||||
setTimeout(connectDecode, 5000);
|
setTimeout(connectDecode, 5000);
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
connectDecode();
|
connectDecode();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user