|
|
@@ -15,11 +15,13 @@ class ChatConnectionManager:
|
|
|
if order_id not in self.active_connections:
|
|
|
self.active_connections[order_id] = []
|
|
|
self.active_connections[order_id].append({"ws": websocket, "role": role})
|
|
|
+ print(f"DEBUG: Chat WS connected for Order #{order_id} (Role: {role}). Total connections: {len(self.active_connections[order_id])}")
|
|
|
await self.broadcast_presence(order_id)
|
|
|
|
|
|
def disconnect(self, websocket: WebSocket, order_id: int):
|
|
|
if order_id in self.active_connections:
|
|
|
self.active_connections[order_id] = [c for c in self.active_connections[order_id] if c["ws"] != websocket]
|
|
|
+ print(f"DEBUG: Chat WS disconnected for Order #{order_id}. Remaining: {len(self.active_connections[order_id])}")
|
|
|
if not self.active_connections[order_id]:
|
|
|
del self.active_connections[order_id]
|
|
|
else:
|
|
|
@@ -49,10 +51,13 @@ class ChatConnectionManager:
|
|
|
if "type" not in message:
|
|
|
message["type"] = "message"
|
|
|
payload = json.dumps(message)
|
|
|
+ print(f"DEBUG: Broadcasting to Order #{order_id} to {len(self.active_connections[order_id])} receivers")
|
|
|
for connection in self.active_connections[order_id]:
|
|
|
try:
|
|
|
await connection["ws"].send_text(payload)
|
|
|
- except:
|
|
|
- pass
|
|
|
+ except Exception as e:
|
|
|
+ print(f"DEBUG: Failed to send WS message to a connection: {e}")
|
|
|
+ else:
|
|
|
+ print(f"DEBUG: Attempted broadcast to Order #{order_id} but NO active connections found")
|
|
|
|
|
|
manager = ChatConnectionManager()
|