From 206babb20fd752f50c1f2e196d58f06fe60822b0 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Mon, 25 Aug 2025 18:01:00 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7(backend)=20extract=20LiveKit=20pub?= =?UTF-8?q?lishing=20sources=20to=20Django=20settings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move hardcoded LiveKit publishing sources from backend code to configurable Django settings for better reusability and self-hosting flexibility. Enables self-hosters to customize LiveKit token generation sources without code modifications, improving deployment configurability. --- src/backend/core/utils.py | 22 ++++++++++++++-------- src/backend/meet/settings.py | 10 ++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) 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,