Initial commit from agent
This commit is contained in:
24
core/websocket_manager.py
Normal file
24
core/websocket_manager.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""
|
||||
WebSocket connection manager — handles multiple simultaneous clients.
|
||||
"""
|
||||
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_json(self, data: dict):
|
||||
for connection in self.active_connections:
|
||||
await connection.send_json(data)
|
||||
|
||||
async def broadcast_bytes(self, data: bytes):
|
||||
for connection in self.active_connections:
|
||||
await connection.send_bytes(data)
|
||||
Reference in New Issue
Block a user