This commit is contained in:
Marek Lenczewski
2026-04-07 16:13:16 +02:00
parent 52c4e5f33d
commit 8f15f51bce
32 changed files with 212 additions and 196 deletions

View File

@@ -0,0 +1,24 @@
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
connected_clients: set[WebSocket] = set()
async def notify_clients(profile_ids: list[int]):
message = ",".join(str(pid) for pid in profile_ids)
for client in list(connected_clients):
try:
await client.send_text(message)
except Exception:
connected_clients.discard(client)
def register_websocket(app: FastAPI):
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
connected_clients.add(websocket)
try:
while True:
await websocket.receive_text()
except WebSocketDisconnect:
connected_clients.discard(websocket)