feat: Add WebSocket ping/pong + detailed streaming debug + initial review messages
This commit is contained in:
+26
-3
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user