diff --git a/websocket_connection_manager.py b/websocket_connection_manager.py index 779fdac..64d7b2c 100644 --- a/websocket_connection_manager.py +++ b/websocket_connection_manager.py @@ -13,7 +13,13 @@ async def connect(self, ws: WebSocket): def disconnect(self, ws: WebSocket): self.__active_connections.remove(ws) + async def send_text(self, ws: WebSocket, msg: str): + try: + await ws.send_text(msg) + except: + self.__active_connections.remove(ws) + async def broadcast(self, msg: str): await asyncio.gather( - *[conn.send_text(msg) for conn in self.__active_connections] + *[self.send_text(conn, msg) for conn in self.__active_connections] )