Skip to content

feat: add WebSocket support via Gorilla WebSocket #21

@GRACENOBLE

Description

@GRACENOBLE

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)

Web (Next.js)

  • Add a useWebSocket hook in lib/ 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 WebSocketManager singleton or scoped to a ViewModel
  • Reconnect on network change; pass Firebase token on handshake

Acceptance criteria

  • GET /ws upgrades 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 useWebSocket hook 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.md and web/docs/websocket.md

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions