-
When trying to implement the example from Or it's not possible corrently and I should opon the feature request to Make WebSockets hashable? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Found a solution in FastAPI documentation which uses Starlette's WebSokets so the solution should be same for Starlette. 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 send_personal_message(self, message: str, websocket: WebSocket):
await websocket.send_text(message)
async def broadcast(self, message: str):
for connection in self.active_connections:
await connection.send_text(message) The more detailed explanation for why the example from |
Beta Was this translation helpful? Give feedback.
Found a solution in FastAPI documentation which uses Starlette's WebSokets so the solution should be same for Starlette.