Add real-time WebSocket infrastructure for Pass-the-Aux rooms
There was zero real-time infrastructure anywhere in this backend
before this - LiveRoom only ever supported create/list. Added
WS /social/rooms/{room_id}/ws:
- Chat: broadcast to everyone in the room (including the sender - a
simpler, more predictable rule than asymmetric exclusion; clients
can dedupe by user_id if they update optimistically).
- Reactions + a "fire meter": 🔥 reactions accumulate into a count
that decays over a 30s window (src/services/room_manager.py), so it
reads as "how hot is it right now," not a lifetime total.
- DJ handoff: request_aux queues a listener, pass_aux (DJ-only, an
explicit rejection if a non-DJ tries) hands off to the front of the
queue or a requested user_id. Confirmed via the actual LiveRoom.dj_id
column, not just the in-memory session.
- now_playing (DJ-only) updates LiveRoom.current_song_id live.
- Presence (user_joined/user_left) and an initial state snapshot on
connect (current DJ, current song, who's here, recent chat, fire
count, queue) so a client joining mid-session isn't starting blind.
Room state (connections, chat history, fire events, DJ queue) is
in-memory and ephemeral by design (src/services/room_manager.py) -
only dj_id/current_song_id persist to the DB, since that's the only
part that should still be true if someone checks GET /social/rooms
without being live-connected. An empty room's ephemeral state is
discarded when the last person disconnects.
Found and fixed a real deployment gap while verifying this against the
actual running server rather than just the test suite: uvicorn had no
WebSocket protocol implementation installed at all (no `websockets` or
`wsproto` in requirements.txt) - Starlette's TestClient simulates
WebSockets in-process and doesn't need one, so all 8 new tests passed
happily while the real deployed server would have silently rejected
every WebSocket connection. Added websockets>=13.0 to requirements.txt
and confirmed a real end-to-end session (two live `websockets` client
connections, not TestClient) against the actual running dev instance:
chat, reactions, fire count, aux request/handoff, all working and
persisting to the DB correctly.
Co-Authored-By:
Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCxXmJVvDFJVHTUi4QgNzi
Showing
| ... | ... | @@ -10,6 +10,9 @@ google-generativeai==0.8.3 |
| pedalboard==0.9.8 | ||
| fastapi>=0.110.0 | ||
| uvicorn>=0.28.0 | ||
| websockets>=13.0 # uvicorn's WebSocket protocol implementation - without this, uvicorn | ||
| # silently has no WebSocket support at all (no error, connections just | ||
| # fail); needed for the Pass-the-Aux room websocket routes | ||
| sqlalchemy>=2.0.0 | ||
| httpx>=0.27.0 | ||
| python-multipart>=0.0.9 | ||
| ... | ... |
src/services/room_manager.py
0 → 100644
Please
register
or
sign in
to comment