feat(collector): add websocket

This commit is contained in:
2025-12-28 22:24:23 +03:00
parent 7334855ba2
commit e6f361def4
6 changed files with 252 additions and 49 deletions

View File

@@ -0,0 +1,33 @@
#!/usr/bin/env python3
"""FastAPI WebSocket endpoint for live audio streaming."""
from __future__ import annotations
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
from ws_manager import ConnectionManager
app = FastAPI(title="Audio Analyzer WebSocket")
manager = ConnectionManager()
@app.get("/health")
async def health() -> dict[str, str]:
"""Health check endpoint."""
return {"status": "ok"}
@app.websocket("/ws/live")
async def ws_live(websocket: WebSocket) -> None:
"""WebSocket endpoint for real-time audio data streaming."""
await manager.connect(websocket)
try:
while True:
# Keep connection alive
await websocket.receive_text()
except WebSocketDisconnect:
pass
except Exception:
pass
finally:
await manager.disconnect(websocket)