Spaces:
Sleeping
Sleeping
| """ | |
| token_server.py — Génération de tokens LiveKit pour l'interface Gradio | |
| """ | |
| import os | |
| import uuid | |
| from dotenv import load_dotenv | |
| from livekit.api import AccessToken, VideoGrants | |
| load_dotenv() | |
| def get_connection_details(room_name: str | None = None) -> dict: | |
| api_key = os.environ.get("LIVEKIT_API_KEY") | |
| api_secret = os.environ.get("LIVEKIT_API_SECRET") | |
| livekit_url = os.environ.get("LIVEKIT_URL") | |
| if not api_key or not api_secret or not livekit_url: | |
| raise ValueError( | |
| "Variables manquantes dans .env : LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET" | |
| ) | |
| room = room_name or f"voice-room-{uuid.uuid4().hex[:8]}" | |
| identity = f"user-{uuid.uuid4().hex[:6]}" | |
| token = ( | |
| AccessToken(api_key=api_key, api_secret=api_secret) | |
| .with_identity(identity) | |
| .with_name(identity) | |
| .with_grants( | |
| VideoGrants( | |
| room_join=True, | |
| room=room, | |
| can_publish=True, | |
| can_subscribe=True, | |
| ) | |
| ) | |
| .to_jwt() | |
| ) | |
| return { | |
| "success": True, | |
| "url": livekit_url, | |
| "token": token, | |
| "room": room, | |
| "identity": identity, | |
| } | |