Make the console speak the backend's telemetry protocol
The telemetry store and the printer card described a protocol no backend
ever spoke. The store expected `{ type, data: { printerId, progressPct,
state } }` with a closed five-value state enum; `/ws/telemetry` sends
`{ type: "printer.telemetry", printer: {...} }` with `id`,
`progressPercent` and an open `status`, and prefaces it with a `ready`
frame. The card also displayed `printer.model`, which the printer
resource has never had - it has `vendor`.
Authentication was the other half: the socket now connects with the
subprotocol list `["bearer", token]`, which is what the backend gates
the upgrade on, and never a query parameter. The token is read from the
session on each attempt, because supabase-js refreshes it hourly and a
reconnect replaying the first token would work right up until it
mattered. With no session it does not connect at all, and app.vue drives
connect/disconnect from the session rather than a one-shot onMounted.
Reconnection is now backed off from 1s to 30s instead of a flat 3s. A
browser cannot see why an upgrade failed - a rejected token and an
unreachable server are both just onerror then onclose - so a token the
server will never accept previously retried every 3s for as long as the
tab stayed open.
`disconnect()` no longer reconnects the socket it just closed, via a
`wanted` flag; handlers from a replaced socket are ignored.
Null is no longer rendered as zero. A claimed printer whose gateway has
never reported has no temperature, and 0 degrees is a different claim:
null readings stay out of the graph's history, the labels show a dash,
the progress bar is omitted rather than drawn empty, and a null status
reads "unknown" rather than the old "offline", which asserted something
nobody had observed. `lastSeenAt` is shown, since it is what separates
an idle printer from one nothing has heard from in an hour.
The card takes one `printer` prop instead of a row plus a `live`
overlay - the push and the REST row are the same shape by design, so
pages/index.vue replaces one with the other and @continuum/ui stays
plain Vue that knows nothing of stores or the API. Status styling now
covers all six values of the backend's printer_status enum; paused and
maintenance previously drew as ordinary text.
Types are hand-mirrored in packages/ui/src/types.ts from
continuum-schemas, the convention this project already uses across
TS and Rust. @continuum/ts-types is in another repository and is not
resolvable here; a `link:` out of the repo would break on any checkout
not laid out like this machine's. Field names are verified identical to
the schema's.
Typechecks clean (nuxt typecheck, vue-tsc). Not exercised at runtime;
the protocol it now implements is the one verified live by
continuum-backend's scripts/e2e-edge.sh.
This commit is contained in:
+26
-18
@@ -1,28 +1,31 @@
|
||||
<script setup lang="ts">
|
||||
import { PrinterCard } from "@continuum/ui";
|
||||
import { PrinterCard, type AppPrinterState } from "@continuum/ui";
|
||||
import { useTelemetryStore } from "~/stores/telemetry";
|
||||
|
||||
interface Printer {
|
||||
id: string;
|
||||
name: string;
|
||||
model: string;
|
||||
farmId: string;
|
||||
/**
|
||||
* Set only for a printer whose camera the gateway can actually restream,
|
||||
* which in a mixed fleet is the minority. Its presence is what decides
|
||||
* whether to ask for a stream URL at all - see the lookup below.
|
||||
*/
|
||||
cameraStream?: string | null;
|
||||
}
|
||||
|
||||
const telemetry = useTelemetryStore();
|
||||
|
||||
const apiFetch = useApiFetch();
|
||||
|
||||
const { data: printers } = await useAsyncData("printers", () =>
|
||||
apiFetch<Printer[]>("/printers"),
|
||||
apiFetch<AppPrinterState[]>("/printers"),
|
||||
);
|
||||
|
||||
// Which row to draw: the live push if there is one, else the fetched row.
|
||||
//
|
||||
// Merged here rather than passing `PrinterCard` a second `live` prop. A push
|
||||
// is the same shape as a `GET /printers` row (that is the contract's whole
|
||||
// point), so the pushed object simply *replaces* the fetched one - replaces,
|
||||
// not spreads, because a push is the complete resource and a spread would let
|
||||
// a field the push omitted survive from the older row. The page does this
|
||||
// rather than the component because `@continuum/ui` is plain Vue that knows
|
||||
// nothing of stores or the API, so it can render in a test or the Tauri shell
|
||||
// with no server. Known edge: a push that predates a refetch can briefly
|
||||
// shadow the fresher row; the next push corrects it.
|
||||
// The REST list still decides *which* printers exist and in what order.
|
||||
function current(printer: AppPrinterState): AppPrinterState {
|
||||
return telemetry.printers[printer.id] ?? printer;
|
||||
}
|
||||
|
||||
// Looked up per printer, because the answer is per printer, but only for the
|
||||
// printers the list already says have a camera. Asking for all of them would
|
||||
// mean one request per machine in the fleet, most of them 404 by design.
|
||||
@@ -54,12 +57,17 @@ watch(
|
||||
<PrinterCard
|
||||
v-for="printer in printers ?? []"
|
||||
:key="printer.id"
|
||||
:printer="printer"
|
||||
:live="telemetry.printers[printer.id]"
|
||||
:printer="current(printer)"
|
||||
:stream="streams[printer.id]"
|
||||
/>
|
||||
</div>
|
||||
<p v-if="!printers?.length">No printers registered yet.</p>
|
||||
<p v-if="!printers?.length">
|
||||
<template v-if="telemetry.link !== 'connected' || telemetry.visiblePrinters === null">
|
||||
No printers loaded yet.
|
||||
</template>
|
||||
<template v-else-if="telemetry.visiblePrinters === 0">No printers registered yet.</template>
|
||||
<template v-else>Printers exist but none has been listed - try refreshing.</template>
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user