from __future__ import annotations

from fastapi import APIRouter, WebSocket
from fastapi.websockets import WebSocketDisconnect

from app.services.ws_hub import hub

router = APIRouter()


@router.websocket("/ws/logs")
async def websocket_logs(websocket: WebSocket) -> None:
    await hub.connect(websocket)
    try:
        while True:
            await websocket.receive_text()
    except WebSocketDisconnect:
        hub.disconnect(websocket)
    except Exception:
        hub.disconnect(websocket)
