18 lines
562 B
Python
18 lines
562 B
Python
# app/routes/websocket.py
|
|
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
|
from app.services.stream_manager import reset_stream_time
|
|
|
|
router = APIRouter()
|
|
|
|
@router.websocket("/ws")
|
|
async def websocket_endpoint(websocket: WebSocket):
|
|
await websocket.accept()
|
|
try:
|
|
while True:
|
|
json_msg = await websocket.receive_json()
|
|
if json_msg:
|
|
reset_stream_time(json_msg.get("looking"))
|
|
await websocket.send_text("ok")
|
|
except WebSocketDisconnect:
|
|
print("WebSocket disconnected")
|