feat(ws): WebSocket channel for real-time stream updates (#49)#111
Merged
Jagadeeshftw merged 2 commits intoFluxora-Org:mainfrom Mar 31, 2026
Merged
Conversation
) - Add src/websockets/streamChannel.ts: ws.Server attached to existing HTTP server at /ws/streams; broadcast(), getConnectionCount(), closeWebSocketServer() exported for use by routes and shutdown - Enforce per-connection rate limit (10 msg / 10 s → close 1008) - Enforce max client message size (4 KiB → close 1009) - Heartbeat ping/pong every 30 s prunes dead connections - Emit stream.created / stream.updated / stream.cancelled events from streamEventService after each successful mutation - GET /health now includes wsConnections count - Register WS teardown via addShutdownHook for graceful shutdown - Add tests/websocket.test.ts: 8 integration tests covering broadcast, multi-client delivery, oversized payload, rate limit, connection count tracking, degraded event, and abrupt disconnect - README: add WebSocket API section with schema, abuse limits, observability notes, manual verification steps, and non-goals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #49
Implements the WebSocket channel for real-time stream updates described in issue #49.
Clients can connect to
ws://<host>/ws/streamsand receive live events whenever astream is created, updated, or cancelled.
Changes
New:
src/websockets/streamChannel.tsws.Serverto the existing HTTP server (no extra port)broadcast(),getConnectionCount(),closeWebSocketServer()10081009connectionIdandtotalModified:
src/services/streamEventService.tsbroadcast()after each successfulStreamCreated,StreamUpdated, andStreamCancelledmutation — single source of truth from the indexerModified:
src/routes/health.tsGET /healthnow includeswsConnections(live client count)Modified:
src/index.tsapp.listen()closeWebSocketServerviaaddShutdownHookfor graceful shutdownNew:
tests/websocket.test.ts8 integration tests covering:
10091008service.degradedevent delivered to clientsModified:
README.mdwscat), and explicit non-goals with follow-up trackingNon-goals (documented, not deferred silently)
Verification
bash
Run new tests
npx vitest run tests/websocket.test.ts
Manual smoke test
npm run dev
wscat -c ws://localhost:3000/ws/streams
In another terminal, create a stream via POST /api/streams and watch the event arrive
Health check includes wsConnections
curl http://localhost:3000/health | jq .wsConnec