| from fastapi import WebSocket | |
| class Manager: | |
| def __init__(self): | |
| self.connections = {} | |
| async def connect(self, ws: WebSocket, client_id: str): | |
| await ws.accept() | |
| self.connections[client_id] = ws | |
| async def send(self, client_id: str, data: dict): | |
| ws = self.connections.get(client_id) | |
| if ws: | |
| await ws.send_json(data) | |
| manager = Manager() | |