diff --git a/src/backend/core/utils.py b/src/backend/core/utils.py index 268a9be0..1a7f34dd 100644 --- a/src/backend/core/utils.py +++ b/src/backend/core/utils.py @@ -7,7 +7,7 @@ Utils functions used in the core app import hashlib import json import random -from typing import Optional +from typing import List, Optional from uuid import uuid4 from django.conf import settings @@ -49,7 +49,11 @@ def generate_color(identity: str) -> str: def generate_token( - room: str, user, username: Optional[str] = None, color: Optional[str] = None + room: str, + user, + username: Optional[str] = None, + color: Optional[str] = None, + sources: Optional[List[str]] = None, ) -> str: """Generate a LiveKit access token for a user in a specific room. @@ -60,21 +64,23 @@ def generate_token( If none, a default value will be used. color (Optional[str]): The color to be displayed in the room. If none, a value will be generated + sources: (Optional[List[str]]): List of media sources the user can publish + If none, defaults to LIVEKIT_DEFAULT_SOURCES. Returns: str: The LiveKit JWT access token. """ + + if sources is None: + sources = settings.LIVEKIT_DEFAULT_SOURCES + video_grants = VideoGrants( room=room, room_join=True, room_admin=True, can_update_own_metadata=True, - can_publish_sources=[ - "camera", - "microphone", - "screen_share", - "screen_share_audio", - ], + can_publish=bool(len(sources)), + can_publish_sources=sources, ) if user.is_anonymous: diff --git a/src/backend/meet/settings.py b/src/backend/meet/settings.py index 3cc95cde..51d10e88 100755 --- a/src/backend/meet/settings.py +++ b/src/backend/meet/settings.py @@ -495,6 +495,16 @@ class Base(Configuration): LIVEKIT_FORCE_WSS_PROTOCOL = values.BooleanValue( False, environ_name="LIVEKIT_FORCE_WSS_PROTOCOL", environ_prefix=None ) + LIVEKIT_DEFAULT_SOURCES = values.ListValue( + [ + "camera", + "microphone", + "screen_share", + "screen_share_audio", + ], + environ_name="LIVEKIT_DEFAULT_SOURCES", + environ_prefix=None, + ) LIVEKIT_ENABLE_FIREFOX_PROXY_WORKAROUND = values.BooleanValue( environ_name="LIVEKIT_ENABLE_FIREFOX_PROXY_WORKAROUND", environ_prefix=None,