Frontend: WS client singleton with reconnect #41
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The frontend needs a single WebSocket connection that persists across the multiplayer flow.
Files to create
apps/web/src/lib/ws-client.tsKey features
connect(url)— establish connection with auth cookies.disconnect()— clean close.send(message)— typed message (validated against shared Zod schemas).on(type, handler)/off(type, handler)— event handlers.Acceptance criteria
@lila/sharedschemasNotes
WebSocket URL:
wss://api.lilastudy.com(prod),ws://localhost:3000(dev). Derive fromimport.meta.env.VITE_API_URL. Consider Zustand for connection state (app already uses Zustand).