This commit is contained in:
Marek Lenczewski
2026-04-07 17:55:30 +02:00
parent 8f15f51bce
commit ca988345e9
19 changed files with 201 additions and 203 deletions

View File

@@ -1,24 +1,26 @@
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
connected_clients: set[WebSocket] = set()
connectedClients: 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):
async def notifyClients(profileId: int | None):
if not profileId:
profileId = 1
message = str(profileId)
for client in list(connectedClients):
try:
await client.send_text(message)
except Exception:
connected_clients.discard(client)
connectedClients.discard(client)
def register_websocket(app: FastAPI):
def registerWebsocket(app: FastAPI):
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
async def websocketEndpoint(websocket: WebSocket):
await websocket.accept()
connected_clients.add(websocket)
connectedClients.add(websocket)
try:
while True:
await websocket.receive_text()
except WebSocketDisconnect:
connected_clients.discard(websocket)
connectedClients.discard(websocket)