[fix](trx-frontend-http): keep the rig names through the state stream
The picker and the header showed each rig's lowercase id instead of its configured name. applyRigList takes the names as a parameter defaulted to an empty map, and the state-update path passes only the rig ids — names come from /rigs, not from a state frame — so that call landed on the default and the body, which treats "an object" as "here are the names", cleared them. One frame after load the names were gone for the rest of the session. Omitted now means no news rather than no names. The fixture is why this was invisible: it pushed an identical status payload every tick and the client skips a frame equal to the last, so render never ran and neither did the call that did the damage. Its event stream varies between frames now, as a real one does. Which immediately caught a second fault: state frames arrive continuously, and one sent before the server applied a new squelch threshold snapped the line back to where it had just been dragged from. A local change outranks the echo for two seconds, the same idea as the optimistic frequency guard beside it. The fixture also records what /set_sdr_squelch sets and reports it back afterwards — the drag test had been passing against a server that ignored the write. Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
@@ -237,6 +237,18 @@ export async function startWebFixture({
|
||||
|
||||
const server = http.createServer(async (request, response) => {
|
||||
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
||||
// Setting a control means the next status carries the new value, the way a
|
||||
// real server echoes what it applied.
|
||||
if (url.pathname === "/set_sdr_squelch") {
|
||||
const enabled = url.searchParams.get("enabled") === "true";
|
||||
const threshold = Number(url.searchParams.get("threshold_db"));
|
||||
if (status.filter) {
|
||||
status.filter.sdr_squelch_enabled = enabled;
|
||||
if (Number.isFinite(threshold)) status.filter.sdr_squelch_threshold_db = threshold;
|
||||
}
|
||||
response.writeHead(200).end();
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/select_rig" && request.method === "POST") {
|
||||
const remote = url.searchParams.get("remote");
|
||||
if (remote) {
|
||||
@@ -324,6 +336,28 @@ export async function startWebFixture({
|
||||
request.on("close", () => clearInterval(timer));
|
||||
return;
|
||||
}
|
||||
// The real server pushes rig state here every second or so; serving an
|
||||
// open-but-silent stream meant nothing in the client's state-update path
|
||||
// was ever exercised.
|
||||
if (url.pathname === "/events") {
|
||||
response.writeHead(200, {
|
||||
"cache-control": "no-cache",
|
||||
connection: "keep-alive",
|
||||
"content-type": "text/event-stream",
|
||||
});
|
||||
// Varying, as a real one is: the client skips a frame identical to the
|
||||
// last, so a repeated payload exercises none of the state-update path.
|
||||
const frame = () => JSON.stringify({
|
||||
...status,
|
||||
status: { ...status.status, freq: { hz: 100_000_000 + (Date.now() % 1000) } },
|
||||
});
|
||||
response.write(`data: ${frame()}\n\n`);
|
||||
const timer = setInterval(() => {
|
||||
response.write(`data: ${frame()}\n\n`);
|
||||
}, 700);
|
||||
request.on("close", () => clearInterval(timer));
|
||||
return;
|
||||
}
|
||||
if (["/events", "/decode", "/spectrum", "/meter"].includes(url.pathname)) {
|
||||
response.writeHead(200, {
|
||||
"cache-control": "no-cache",
|
||||
|
||||
Reference in New Issue
Block a user