Files
ASF_tools/asf-cloud-server/testarena/backend/app/socket_manager.py
2025-11-24 02:14:25 +01:00

23 lines
653 B
Python

from fastapi import WebSocket
from typing import List
class ConnectionManager:
def __init__(self):
self.active_connections: List[WebSocket] = []
async def connect(self, websocket: WebSocket):
await websocket.accept()
self.active_connections.append(websocket)
def disconnect(self, websocket: WebSocket):
self.active_connections.remove(websocket)
async def broadcast(self, message: str):
for connection in self.active_connections:
try:
await connection.send_text(message)
except:
self.disconnect(connection)
manager = ConnectionManager()