Repository navigation
feat: add WebSocket support via Gorilla WebSocket #21
Copy link
Copy link
Closed
Description
Summary
Add real-time bidirectional communication to the backend using github.com/gorilla/websocket, enabling the web and mobile clients to receive live updates without polling.
Scope
Backend (Go)
- Add
github.com/gorilla/websocketdependency - Add a
WebSocketHubininternal/infrastructure/ws/that manages connected clients, broadcasts messages, and handles disconnections - Expose a
GET /wsupgrade endpoint inroutes.go— authenticated via Firebase token query param orUpgradeheader (ties into feat: add Firebase Authentication across all app layers #15) - Wire the Hub into
server.goas a long-lived goroutine alongside the HTTP server - Publish events to the Hub from Asynq workers or Redis Streams consumers (feat: integrate Asynq + Redis Streams for background jobs and event-driven messaging #18) so job completions and domain events reach connected clients in real time
Web (Next.js)
- Add a
useWebSockethook inlib/that opens the connection, handles reconnection with exponential backoff, and exposes incoming messages - Attach the Firebase ID token on connect for authentication
- Typed message envelope:
{ type: string; payload: unknown }— discriminated union for known event types
Mobile (Android / Jetpack Compose)
- Add OkHttp WebSocket client (already available transitively via Retrofit/OkHttp)
- Manage the connection in a
WebSocketManagersingleton or scoped to a ViewModel - Reconnect on network change; pass Firebase token on handshake
Acceptance criteria
-
GET /wsupgrades to a WebSocket connection and rejects unauthenticated requests with 401 - Hub broadcasts a message to all connected clients when an event is published (e.g. job completed from feat: integrate Asynq + Redis Streams for background jobs and event-driven messaging #18)
- Web
useWebSockethook receives and surfaces live messages in a component - Android client receives live messages while foregrounded
- Hub cleans up disconnected clients without goroutine leaks
- Hub tested with concurrent connect/disconnect/broadcast (unit test with mock conns)
- Docs added to
backend/docs/websocket.mdandweb/docs/websocket.md
Dependencies
- feat: add Firebase Authentication across all app layers #15 Firebase Auth — token validated on WebSocket handshake
- feat: integrate Asynq + Redis Streams for background jobs and event-driven messaging #18 Asynq + Redis Streams — job/event completions are the primary broadcast trigger
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
feat(websocket): add real-time WebSocket support via gorilla/websocket