1.4 KiB
1.4 KiB
WebSocket Chat - Feature Specification
Overview
Add WebSocket support to the chat-api service. GET /ws upgrades to a WebSocket connection. Incoming messages are published to a Redis Pub/Sub channel. A Redis subscriber broadcasts received messages to all connected WebSocket clients.
Requirements
Functional Requirements
- WebSocket Endpoint:
GET /api/chat-api/wsupgrades HTTP connections to WebSocket - Message Publishing: Incoming WebSocket messages are published to Redis Pub/Sub channels
- Message Broadcasting: A Redis subscriber receives messages and broadcasts them to all connected WebSocket clients
- Room Support: Optional room-based messaging via
GET /api/chat-api/ws/{room}or?room=query parameter
Non-Functional Requirements
- Uses existing
pkg/realtimepackage (Hub, WSClient, RedisBroadcaster) - Follows existing chat-api handler and routing patterns
- Redis connection configured via
REDIS_URLenvironment variable - Graceful shutdown of hub and Redis broadcaster on SIGTERM
Acceptance Criteria
GET /api/chat-api/wsupgrades to WebSocket- Messages sent by a client are published to Redis
- Messages from Redis are broadcast to all connected clients
- Hub and Redis broadcaster shut down gracefully
- Configuration via
REDIS_URLenvironment variable - OpenAPI spec updated with WebSocket endpoint documentation