Initial scaffold: React+TS+Vite frontend, FastAPI backend, config system
This commit is contained in:
19
backend/routes/ws_routes.py
Normal file
19
backend/routes/ws_routes.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
||||
from mqtt_bridge import register_ws_client, unregister_ws_client
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.websocket("/api/ws/events")
|
||||
async def websocket_events(ws: WebSocket):
|
||||
await ws.accept()
|
||||
register_ws_client(ws)
|
||||
try:
|
||||
while True:
|
||||
# Keep connection alive, handle client messages if needed
|
||||
data = await ws.receive_text()
|
||||
# Client can send ping/keepalive
|
||||
except WebSocketDisconnect:
|
||||
pass
|
||||
finally:
|
||||
unregister_ws_client(ws)
|
||||
Reference in New Issue
Block a user