Files
youtube-app/backend/notify/notify_clients.py
Marek Lenczewski 8f15f51bce update
2026-04-07 16:13:16 +02:00

25 lines
748 B
Python

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)