feat: Add WebSocket ping/pong + detailed streaming debug + initial review messages

This commit is contained in:
Primakov Alexandr Alexandrovich
2025-10-13 10:30:56 +03:00
parent 3df9e61b55
commit a27a0fa0f0
3 changed files with 169 additions and 47 deletions
+26 -3
View File
@@ -122,14 +122,37 @@ async def health_check():
async def websocket_endpoint(websocket: WebSocket):
"""WebSocket endpoint for real-time review updates"""
await manager.connect(websocket)
print(f"✅ WebSocket connected. Total connections: {len(manager.active_connections)}")
try:
# Send welcome message
await websocket.send_json({
"type": "connection",
"status": "connected",
"message": "WebSocket подключен к серверу review",
"timestamp": __import__('datetime').datetime.utcnow().isoformat()
})
while True:
# Keep connection alive
# Keep connection alive and handle client messages
data = await websocket.receive_text()
# Echo back or handle client messages if needed
await websocket.send_json({"type": "pong", "message": "connected"})
print(f"📨 Received from client: {data}")
# Handle ping/pong
if data == "ping":
await websocket.send_json({
"type": "pong",
"timestamp": __import__('datetime').datetime.utcnow().isoformat()
})
else:
# Echo back for debugging
await websocket.send_json({
"type": "echo",
"message": f"Получено: {data}"
})
except WebSocketDisconnect:
manager.disconnect(websocket)
print(f"❌ WebSocket disconnected. Remaining connections: {len(manager.active_connections)}")
async def broadcast_review_update(review_id: int, event_type: str, data: dict = None):