This site uses one functional cookie to keep feature rollouts consistent for you. Nothing is set until you choose. See the privacy notice.
Dev notes
I wanted to practise the kind of screen where a wrong or missing update has a real cost: live tracks on a 3D map, a camera tile and an alert queue, fed by a stream. Every number is fake. The decisions about what the screen does when the data is bad are not, and this page is those decisions, with what I turned down and what each one costs.
I started from the person, not the map. Someone watching a field picture is partway through something else: a radio in one hand, a small screen, a bad link, maybe gloves. They are not exploring. They are asking three questions over and over: where is everyone, is anything wrong, and can I trust what I am looking at right now. Every decision below is an answer to the third one.
What I prioritised, in order: honesty about data quality, then a missed alert being hard to do by accident, then working with a keyboard and a screen reader, then working on a thin link, then looking good. The map is last on purpose. It is the part that gets noticed and the part that matters least when something goes wrong.
The shape is a chain with one job per link. portfolio_api owns the feed: a pure function of the clock behind /api/field-ops/snapshot and an SSE /stream. The Next app proxies both same-origin, which is the pattern every other route here already uses, so the backend address never reaches the browser. A hook (useFieldOpsFeed) owns the connection and tells the truth about it. A pure reducer (feedState) owns what the screen believes. The console, the map and the video tile only render that belief.
The order I thought in was the order of failure, not the order of data. First what the screen must never get wrong (stale looks fresh, an alert slips by), then where that logic can live so a test can reach it without a browser (the reducer and the simulation, both pure), then the thin impure edges around them (the stream and the WebGL canvas). That is why the two files with the most behaviour have no framework in them.
One wrong turn is worth keeping. My first plan put the endpoints in the Next app as route handlers, because that was the smallest thing with no second deploy. I moved them to portfolio_api because the point of the exercise is a client talking to a backend across a real boundary, and a feed that lives inside the page's own server skips exactly the failures I wanted to handle: a proxy that buffers, a backend that is down, a stream that gets cut. The cost is a deploy order (backend first) and a proxy hop, and I would pay it again.
I also tested it the way it runs, not just through unit tests: the real router behind compression, behind the Next proxy, read with curl and then in a browser. That caught nothing this time, but it is the check that would have caught a buffered stream, and the unit tests cannot.
I chose: A track that stops reporting keeps its last position, is drawn as a wireframe, and says STALE with its age in words.
Instead of: Removing it from the map after a timeout, or fading it with colour alone.
Good: Nobody mistakes an empty patch of map for an empty field. The screen says what it knows and how old that is.
Costs me: The map can look cluttered with ghosts, and I had to pick a threshold (10 seconds) with no real operational number behind it.
I chose: A critical alert sorts first and stays until someone presses Acknowledge. Nothing clears it on a timer, and a repeat of it in the next update does not reset it.
Instead of: Auto-dismissing toasts, or clearing an alert when the condition stops being true.
Good: Missing one takes an action, not a distraction. The log of what was acknowledged is honest.
Costs me: A noisy feed fills the queue with things someone has to touch. That is the right failure, but it means alert volume has to be designed, not hoped for.
I chose: Every fact on the map is also a button in the track list, with the same status in words. The map is labelled as a picture of that list.
Instead of: A map-first design where selecting means clicking a marker in WebGL.
Good: Works from the keyboard and a screen reader, survives WebGL failing, and is faster to scan than hunting for a marker.
Costs me: Two ways to see the same thing, so I have to keep them in step. A single reducer feeds both, which is why that stays cheap.
I chose: Shape for what a track is (box, cone, diamond), text for its state, and a severity word on every alert.
Instead of: Red, amber and green on identical dots.
Good: Readable in sunlight, in a colour-blind palette, and when I am wrong about the contrast.
Costs me: More visual vocabulary to teach, and shapes get small at a distance.
I chose: The simulation lives in portfolio_api as GET /api/field-ops/snapshot and an SSE GET /api/field-ops/stream. The Next app proxies them same-origin.
Instead of: Route handlers inside the Next app, or a mock that lives only in the browser.
Good: The client talks to a real network boundary, so reconnects, buffering and failure are real. The backend owns the feed the way a real one would.
Costs me: Two PRs and a deploy order to respect, and a proxy hop that can buffer a stream if I am careless. I set no-transform on both sides for that.
I chose: One-way SSE through EventSource.
Instead of: WebSockets, or polling the snapshot every second.
Good: Reconnect, retry delay and framing come with the browser. It is plain HTTP, so it goes through the proxy and compression rules I already have. The data only flows one way, so I do not need a duplex channel.
Costs me: No client-to-server messages on the same channel. Acknowledging an alert is local state today, and a real one would POST it. Browsers also cap open connections per origin on old HTTP versions.
I chose: The clock goes in, the whole picture comes out, nothing is stored.
Instead of: A stateful simulator ticking in memory, or rows in Postgres.
Good: Every instance agrees, it is testable with no sockets or timers, and there is no migration.
Costs me: No history, so no track trails. That is the next thing an operator would ask for and it would need state.
I chose: Updates land once a second into a reducer. Markers ease toward their targets inside useFrame, so React renders once per message and WebGL animates in between.
Instead of: Setting positions in state every frame, or snapping markers on each update.
Good: The page stays responsive as data streams in, and a dropped frame never delays handling an alert.
Costs me: What is drawn is slightly behind what was received. For a real system I would show the report time next to the marker, which the list already does.
I chose: One checkbox reopens the stream at one update every 5 seconds and pauses the video tile first.
Instead of: Detecting the connection type automatically.
Good: The operator knows why the screen got slower, and video is the cheapest thing to give up first.
Costs me: Someone has to turn it on. Detecting a bad link and offering the switch would be a kindness I have not built.
I chose: Live while updates arrive, Reconnecting when the stream errors, Offline with the age of the picture after 15 quiet seconds.
Instead of: Trusting the connection event alone.
Good: It works whatever the cause, because it measures what matters: how old what you are looking at is.
Costs me: A genuinely quiet field and a dead link look the same until I add a heartbeat frame.
Real tactical systems exchange messages in schemas like Cursor on Target, the XML that TAK clients use. I have not built on TAK. This console mimics the shape of the problem, which is a stream of position reports and alerts with a report time on every one, and the report time is exactly what the stale check leans on. If I wired this to a real feed, the work would be mapping that schema into the three types in types.ts and nothing else would change.
Other things on my mind: what happens at 500 tracks (the list needs virtualising and the markers need instancing, since six meshes do not predict five hundred), how to avoid alert fatigue (grouping, rate limits, and not letting a cry-wolf source bury a real one), what a clock skew between device and server does to staleness, and how to cache the last picture so a reload on a dead link is not a blank page.
What time it is. Staleness compares a track's report time with now, and the browser's clock and the server's clock disagree. I carry the server's time forward with the local clock between updates, so the comparison stays on the server's timeline. It is a patch, not a proof: if the device clock jumps, the carried time jumps with it.
EventSource says very little. Its error event does not say why, or whether it will retry. So the hook does not try to read the cause. It tracks the one thing it can measure, how long since anything arrived, and derives the status from that.
A stream through a proxy. Compression middleware and framework proxies like to buffer a response until it is big enough, which turns a live feed into a burst every half minute. Marking both hops no-transform is what stops it. I only trust that because I ran the real router behind compression and read it through the proxy with curl.
Testing something that never finishes. A page with an open stream never reaches network idle, so the usual wait-for-idle in a browser script just times out. I wait for the page to load and then for the thing I actually care about.
React and a clock. Reading the time in render is flagged as impure, and setting state in an effect is blocked by a lint rule here. The clock starts from a lazy initial value and ticks from an interval callback, which is the shape both rules accept and is the right shape anyway.
Picking numbers with nothing to ground them. Ten seconds to call a track stale, fifteen to call the link offline, fifty-five to close the stream. They are reasonable and they are guesses. In a real system they come from the radios and the mission, not from me.
I would rather say these plainly than have someone find them.
High stakes: the stale marker and the acknowledge-only alerts. Both are the same idea: the screen must never show a comfortable lie.
User empathy: I designed for someone with one free hand and a bad link before I designed the map, which is why the list leads and the map follows.
Practical problem solving: the brief was vague, so I picked the smallest thing that has a real stream, a real failure mode and a real operator action, and wrote down what I cut. I can say what is fake and why that is fine.
Offline and low bandwidth: the offline status, the slow stream and the paused video. What I did not do is cache the last picture across reloads, and I would say so.
Update — November 25, 2026
The first version of the camera tile was a dark box with one line of text. I called it a placeholder and moved on. Looking at it on a screenshot, I saw it broke the rule the rest of the page is built on.
A track could go STALE in the list and wireframe on the map while the tile beside them still said it was receiving video from it. Three surfaces, two of them telling the truth. A placeholder was the excuse, and it looked harmless because nothing in the tile could change. That is exactly why it was wrong: a screen that cannot show a bad state will show a good one.
before: Receiving video from Charlie 3 (always, even 20s after the last report) after: NO SIGNAL, last frame 14s ago (frozen, dimmed, same threshold as the map)
The fix was not a new rule. The tile takes the same isStale answer the map and the list already use, so the three cannot disagree. It also overlays the selected track's heading, speed, altitude and the age of the frame, which is what makes it read as a camera on a track rather than a grey rectangle.
It is still not video. There is no buffering state, no frame-rate drop, and no stalled-then-recovered case. Those are different failures from a track going quiet, and I would want a real stream to know what they look like before drawing them.
Update — November 25, 2026
I moved the feed from server-sent events to a WebSocket. I had written down that EventSource "reconnects by itself" as the reason to stay on SSE, and that was true and beside the point for a screen where a missed update costs something.
EventSource only asks for what it missed if the server numbered the events, and mine did not. After a drop the stream came back on the current second, and anything raised in the gap was simply never seen. A Reconnecting banner that clears is not the same as a picture that is complete, and I had built the first and called it the second.
Every frame is a whole second of the clock, and the sequence number is that second. Because the simulation is a pure function of time, the server does not store anything to replay: it computes the missed seconds again, capped at 60. The hook keeps the last sequence it saw and reconnects after 1s, 2s, 4s, up to 10s, asking for everything after it.
wss://<api>/api/field-ops/socket?since=100
{"sequence":101,"snapshot":{...}} <- the second I missed
{"sequence":102,"snapshot":{...}} <- live againA Next route handler cannot upgrade a connection, so the socket goes from the browser straight to portfolio_api. The origin has to be on the allowlist at the handshake, the CSP has to allow the ws form of the API address, and the stream proxy I wrote last week is deleted. I could have kept SSE and added event ids instead, which is less code. I chose the socket because I wanted to build the reconnect path properly, and I would not claim it was the smaller option.
The server tests run a real socket and check order, the cap and the 403. The hook tests use a stub WebSocket with fake timers. I have not watched it reconnect in a browser against a deployed API, or through the production proxy.
Update — November 26, 2026
Every new alert made the page taller. After a few minutes the newest ones sat below the fold, and scrolling down to read them took the map off the screen. On a console the whole picture has to stay in view, so that was a bug, not something to tidy later.
The alerts and tracks shared a grid row with the map and camera, and a grid row is as tall as its tallest cell. So the alert list set the height of the page. I took the side column out of the row's sizing, so it now takes the map column's height, and the alert queue scrolls inside it. The queue can be focused, so it scrolls from the keyboard too, and its heading stays pinned while it scrolls.
With the queue fixed, the page was still 162px taller than a 900px window, with no alerts at all. The camera tile was a full 16:9 frame, about 400px tall for a picture that is still a stand-in. On wide screens the console now takes the window's height, the map stretches to fill what is left, and the camera gets a fixed 224px. Even then it was 1px over, because the header is 56px plus a 1px rule under it. The heights, measured with 30 alerts sent in:
before viewport: 900 pageHeight: 2761 alertQueue: 2228 of 2228 shown after viewport: 900 pageHeight: 900 alertQueue: 367 of 2228 shown
My component tests had no layout to measure, which is how the bug got through. The new check is a Playwright test that fakes the socket with page.routeWebSocket, sends 30 alerts, and fails if the page is taller than the window. Under 1024px wide the console is still one column that scrolls, with the alert queue capped at 384px. I have not tested a window shorter than 704px, where the console stops shrinking and the page scrolls again.