Initial commit: RehearsalHub POC
Full-stack self-hosted band rehearsal platform: Backend (FastAPI + SQLAlchemy 2.0 async): - Auth with JWT (register, login, /me, settings) - Band management with Nextcloud folder integration - Song management with audio version tracking - Nextcloud scan to auto-import audio files - Band membership with link-based invite system - Song comments - Audio analysis worker (BPM, key, loudness, waveform) - Nextcloud activity watcher for auto-import - WebSocket support for real-time annotation updates - Alembic migrations (0001–0003) - Repository pattern, Ruff + mypy configured Frontend (React 18 + Vite + TypeScript strict): - Login/register page with post-login redirect - Home page with band list and creation form - Band page with member panel, invite link, song list, NC scan - Song page with waveform player, annotations, comment thread - Settings page for per-user Nextcloud credentials - Invite acceptance page (/invite/:token) - ESLint v9 flat config + TypeScript strict mode Infrastructure: - Docker Compose: PostgreSQL, Redis, API, worker, watcher, nginx - nginx reverse proxy for static files + /api/ proxy - make check runs all linters before docker compose build Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
46
api/src/rehearsalhub/ws.py
Normal file
46
api/src/rehearsalhub/ws.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""WebSocket connection manager for real-time version room events."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import uuid
|
||||
from typing import Any
|
||||
|
||||
from fastapi import WebSocket
|
||||
|
||||
|
||||
class ConnectionManager:
|
||||
def __init__(self) -> None:
|
||||
# version_id -> list of active WebSocket connections
|
||||
self._rooms: dict[str, list[WebSocket]] = {}
|
||||
|
||||
async def connect(self, version_id: uuid.UUID, websocket: WebSocket) -> None:
|
||||
await websocket.accept()
|
||||
key = str(version_id)
|
||||
self._rooms.setdefault(key, []).append(websocket)
|
||||
|
||||
def disconnect(self, version_id: uuid.UUID, websocket: WebSocket) -> None:
|
||||
key = str(version_id)
|
||||
room = self._rooms.get(key, [])
|
||||
if websocket in room:
|
||||
room.remove(websocket)
|
||||
if not room:
|
||||
self._rooms.pop(key, None)
|
||||
|
||||
async def broadcast(self, version_id: uuid.UUID, event: str, data: Any) -> None:
|
||||
key = str(version_id)
|
||||
payload = json.dumps({"event": event, "data": data})
|
||||
dead: list[WebSocket] = []
|
||||
for ws in self._rooms.get(key, []):
|
||||
try:
|
||||
await ws.send_text(payload)
|
||||
except Exception:
|
||||
dead.append(ws)
|
||||
for ws in dead:
|
||||
self.disconnect(version_id, ws)
|
||||
|
||||
def room_size(self, version_id: uuid.UUID) -> int:
|
||||
return len(self._rooms.get(str(version_id), []))
|
||||
|
||||
|
||||
manager = ConnectionManager()
|
||||
Reference in New Issue
Block a user