🔧(backend) extract LiveKit publishing sources to Django settings

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.
This commit is contained in:
lebaudantoine
2025-08-25 18:01:00 +02:00
committed by aleb_the_flash
parent 081c860e04
commit 206babb20f
2 changed files with 24 additions and 8 deletions

View File

@@ -7,7 +7,7 @@ Utils functions used in the core app
import hashlib import hashlib
import json import json
import random import random
from typing import Optional from typing import List, Optional
from uuid import uuid4 from uuid import uuid4
from django.conf import settings from django.conf import settings
@@ -49,7 +49,11 @@ def generate_color(identity: str) -> str:
def generate_token( 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: ) -> str:
"""Generate a LiveKit access token for a user in a specific room. """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. If none, a default value will be used.
color (Optional[str]): The color to be displayed in the room. color (Optional[str]): The color to be displayed in the room.
If none, a value will be generated 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: Returns:
str: The LiveKit JWT access token. str: The LiveKit JWT access token.
""" """
if sources is None:
sources = settings.LIVEKIT_DEFAULT_SOURCES
video_grants = VideoGrants( video_grants = VideoGrants(
room=room, room=room,
room_join=True, room_join=True,
room_admin=True, room_admin=True,
can_update_own_metadata=True, can_update_own_metadata=True,
can_publish_sources=[ can_publish=bool(len(sources)),
"camera", can_publish_sources=sources,
"microphone",
"screen_share",
"screen_share_audio",
],
) )
if user.is_anonymous: if user.is_anonymous:

View File

@@ -495,6 +495,16 @@ class Base(Configuration):
LIVEKIT_FORCE_WSS_PROTOCOL = values.BooleanValue( LIVEKIT_FORCE_WSS_PROTOCOL = values.BooleanValue(
False, environ_name="LIVEKIT_FORCE_WSS_PROTOCOL", environ_prefix=None 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( LIVEKIT_ENABLE_FIREFOX_PROXY_WORKAROUND = values.BooleanValue(
environ_name="LIVEKIT_ENABLE_FIREFOX_PROXY_WORKAROUND", environ_name="LIVEKIT_ENABLE_FIREFOX_PROXY_WORKAROUND",
environ_prefix=None, environ_prefix=None,