add websocket market
This commit is contained in:
19
app/api/marketplace_ws.py
Normal file
19
app/api/marketplace_ws.py
Normal file
@ -0,0 +1,19 @@
|
||||
from fastapi import APIRouter, WebSocket, WebSocketDisconnect, Query
|
||||
from app.realtime.marketplace_hub import marketplace_hub
|
||||
|
||||
router = APIRouter(tags=["Marketplace WS"])
|
||||
|
||||
@router.websocket("/ws/marketplace")
|
||||
async def marketplace_ws(
|
||||
websocket: WebSocket,
|
||||
server_ip: str = Query(...),
|
||||
):
|
||||
await marketplace_hub.connect(server_ip, websocket)
|
||||
try:
|
||||
# Можно принимать сообщения от клиента, но нам не обязательно.
|
||||
while True:
|
||||
await websocket.receive_text()
|
||||
except WebSocketDisconnect:
|
||||
pass
|
||||
finally:
|
||||
await marketplace_hub.disconnect(server_ip, websocket)
|
||||
Reference in New Issue
Block a user