[feat](trx-frontend-http): consume server-side APRS/CW decode via SSE
Add /decode SSE endpoint streaming decoded messages from the server. Add decode channel OnceLock with set/subscribe pattern. In the browser, connect to /decode EventSource and dispatch to onServerAprs/onServerCw handlers. APRS and CW plugins now receive server-decoded data automatically while keeping browser-side decoding as a fallback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
@@ -643,7 +643,34 @@ for (let i = aprsPacketHistory.length - 1; i >= 0; i--) {
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-start APRS if it was running before page refresh
|
||||
// --- Server-side APRS decode handler ---
|
||||
window.onServerAprs = function(pkt) {
|
||||
addAprsPacket({
|
||||
srcCall: pkt.src_call,
|
||||
destCall: pkt.dest_call,
|
||||
path: pkt.path,
|
||||
info: pkt.info,
|
||||
type: pkt.packet_type,
|
||||
crcOk: pkt.crc_ok,
|
||||
lat: pkt.lat,
|
||||
lon: pkt.lon,
|
||||
symbolTable: pkt.symbol_table,
|
||||
symbolCode: pkt.symbol_code,
|
||||
});
|
||||
};
|
||||
|
||||
// Update status display based on server decode availability
|
||||
function updateAprsStatus() {
|
||||
if (typeof decodeConnected !== "undefined" && decodeConnected) {
|
||||
if (!aprsActive) {
|
||||
aprsStatus.textContent = "Server decode active";
|
||||
aprsToggleBtn.textContent = "Start APRS (browser)";
|
||||
}
|
||||
}
|
||||
}
|
||||
setInterval(updateAprsStatus, 2000);
|
||||
|
||||
// Auto-start APRS if it was running before page refresh (browser fallback)
|
||||
if (loadSetting("aprsRunning", false) && hasWebCodecs) {
|
||||
startAprs();
|
||||
}
|
||||
|
||||
@@ -457,3 +457,40 @@ cwToggleBtn.addEventListener("click", startCw);
|
||||
document.getElementById("cw-clear-btn").addEventListener("click", () => {
|
||||
cwOutputEl.innerHTML = "";
|
||||
});
|
||||
|
||||
// --- Server-side CW decode handler ---
|
||||
let cwLastAppendTime = 0;
|
||||
window.onServerCw = function(evt) {
|
||||
if (evt.text) {
|
||||
// Append decoded text to output
|
||||
const now = Date.now();
|
||||
if (!cwOutputEl.lastElementChild || now - cwLastAppendTime > 10000 || evt.text === "\n") {
|
||||
const line = document.createElement("div");
|
||||
line.className = "cw-line";
|
||||
cwOutputEl.appendChild(line);
|
||||
}
|
||||
cwLastAppendTime = now;
|
||||
const lastLine = cwOutputEl.lastElementChild;
|
||||
if (lastLine) {
|
||||
lastLine.textContent += evt.text;
|
||||
}
|
||||
while (cwOutputEl.children.length > CW_MAX_LINES) {
|
||||
cwOutputEl.removeChild(cwOutputEl.firstChild);
|
||||
}
|
||||
cwOutputEl.scrollTop = cwOutputEl.scrollHeight;
|
||||
}
|
||||
cwSignalIndicator.className = evt.signal_on ? "cw-signal-on" : "cw-signal-off";
|
||||
cwWpmInput.value = evt.wpm;
|
||||
cwToneInput.value = evt.tone_hz;
|
||||
};
|
||||
|
||||
// Update status display based on server decode availability
|
||||
function updateCwStatus() {
|
||||
if (typeof decodeConnected !== "undefined" && decodeConnected) {
|
||||
if (!cwActive) {
|
||||
cwStatusEl.textContent = "Server decode active";
|
||||
cwToggleBtn.textContent = "Start CW (browser)";
|
||||
}
|
||||
}
|
||||
}
|
||||
setInterval(updateCwStatus, 2000);
|
||||
|
||||
Reference in New Issue
Block a user