add voice_rooms
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
from fastapi import APIRouter, WebSocket, WebSocketDisconnect, Query
|
||||
from app.realtime.voice_hub import voice_hub
|
||||
from app.services.voice_rooms import voice_rooms_collection
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@ -9,9 +10,17 @@ async def voice_ws(
|
||||
room_id: str = Query(...),
|
||||
username: str = Query(...)
|
||||
):
|
||||
room = await voice_rooms_collection.find_one({"id": room_id})
|
||||
if not room:
|
||||
await ws.close(code=4004)
|
||||
return
|
||||
if username in voice_hub.rooms.get(room_id, {}):
|
||||
await ws.close(code=4001)
|
||||
return
|
||||
|
||||
if len(voice_hub.rooms.get(room_id, {})) >= room.get("max_users", 5):
|
||||
await ws.close(code=4003)
|
||||
return
|
||||
|
||||
await voice_hub.connect(room_id, username, ws)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user