Repository navigation
Real Time Updates
amalps565 edited this page Sep 30, 2026
·
2 revisions
STOMP over WebSocket at
/ws, published by the backend after each commit and applied by the frontend store.
-
STOMP over WebSocket, handled by Spring's WebSocket support on the server and
@stomp/stompjsin the browser. -
Endpoint:
/ws, plain WebSocket with no SockJS. The Vite dev server proxies it to the backend. -
Auth: send
Authorization: Bearer <jwt>as a STOMP CONNECT header. A CONNECT without a valid JWT gets an ERROR frame and is closed. - Clients may only SUBSCRIBE to
/topic/floors/{floorId}/{date}; SEND is rejected. Heartbeats run every 10 seconds. -
Topic:
/topic/floors/{floorId}/{date}. Clients subscribe to the floor and date they're viewing.
One message per desk change:
{ "deskId": 101, "date": "2026-10-02", "status": "BOOKED", "bookedBy": "Alice Anders", "bookedByUsername": "alice", "seq": 1043 }-
statusisAVAILABLEorBOOKED. -
bookedByandbookedByUsernameare null when the desk becomes available. Messages carry nobookingId; the frontend looks it up withGET /api/bookings/mewhen needed. -
seqcomes from the Postgres sequencedesk_status_seq, increases for every change to a desk, and equals theseqin thePOST /api/bookingsresponse. The frontend marks a desk as yours whenbookedByUsernamematches the signed-in user.
-
Publish only after commit, using
@TransactionalEventListener(phase = AFTER_COMMIT). A booking that rolls back, for example on a 409, is never broadcast. - Send only the desk that changed, never the whole floor.
flowchart TD
Start([Open floor and date]) --> Snap[GET snapshot]
Snap --> Sub[Subscribe to topic]
Sub --> Msg{Update arrives}
Msg -- "seq > stored seq" --> Apply[Patch that desk]
Msg -- "seq <= stored seq" --> Drop[Ignore: stale or duplicate]
Apply --> Msg
Drop --> Msg
Sub -. connection lost .-> Stale[Show 'reconnecting', mark map stale]
Stale --> Re[Reconnect]
Re --> Snap
- Load, then subscribe. Load the snapshot, then apply updates.
-
Drop old updates. Keep the latest
seqper desk and ignore any update with aseqthat isn't greater. This handles messages that arrive out of order or twice. - Resync after reconnecting. Updates sent while the connection was down are lost, so reload the snapshot every time the socket reconnects.
- Show when the map is stale. While disconnected, show a clear indicator.
- Clean up. Unsubscribe when the floor or date changes, and when the page unmounts.
Updates can arrive during the snapshot request. Subscribe first and buffer messages until the snapshot arrives, then apply the buffered ones using the seq rule. Nothing is lost that way.
Repository · The CLAUDE.md files in the repo are the source of truth for rules and the API contract. If this wiki disagrees with them, the repo wins.