29 lines
711 B
Python
29 lines
711 B
Python
from fastapi import APIRouter, Body
|
|
from app.services.voice_rooms import VoiceRoomService
|
|
from app.realtime.voice_hub import voice_hub
|
|
|
|
router = APIRouter(prefix="/api/voice")
|
|
service = VoiceRoomService()
|
|
|
|
|
|
@router.get("/rooms")
|
|
async def list_rooms():
|
|
rooms = await service.list_public_rooms()
|
|
for r in rooms:
|
|
r["users"] = len(voice_hub.rooms.get(r["id"], {}))
|
|
return rooms
|
|
|
|
|
|
@router.post("/rooms")
|
|
async def create_room(
|
|
name: str = Body(...),
|
|
public: bool = Body(True),
|
|
owner: str = Body(...),
|
|
):
|
|
return await service.create_room(name, owner, public)
|
|
|
|
|
|
@router.post("/rooms/join")
|
|
async def join_private(code: str = Body(...)):
|
|
return await service.join_by_code(code)
|