wip generate a random passphrase cached by slug

This commit is contained in:
lebaudantoine
2025-01-04 14:12:45 +01:00
parent 1cf26eec19
commit dd7e3a7c44
4 changed files with 19 additions and 5 deletions
+2 -3
View File
@@ -139,12 +139,11 @@ class RoomSerializer(serializers.ModelSerializer):
"token": utils.generate_token(
room=slug, user=request.user, username=username
),
"passphrase": utils.get_cached_passphrase(slug)
}
output["is_administrable"] = is_admin
output['passphrase'] = "thisisapassphrase"
return output
+15
View File
@@ -14,6 +14,21 @@ from django.conf import settings
from livekit.api import AccessToken, VideoGrants
from functools import lru_cache
import secrets
import string
def generate_random_passphrase(length=26):
"""Generate a random passphrase using letters and digits"""
alphabet = string.ascii_letters + string.digits
return ''.join(secrets.choice(alphabet) for _ in range(length))
@lru_cache()
def get_cached_passphrase(room_slug):
"""Get or generate a cached passphrase for a room slug"""
return generate_random_passphrase()
def generate_color(identity: str) -> str:
"""Generates a consistent HSL color based on a given identity string.
@@ -4,11 +4,11 @@ export type ApiRoom = {
slug: string
is_public: boolean
is_administrable: boolean
passphrase: string
livekit?: {
url: string
room: string
token: string
passphrase: string
}
configuration?: {
[key: string]: string | number | boolean
@@ -110,7 +110,7 @@ export const Conference = ({
}
if (e2eeEnabled) {
keyProvider
.setKey(data.passphrase)
.setKey(data.livekit?.passphrase)
.then(() => {
room.setE2EEEnabled(true).catch((e) => {
if (e instanceof DeviceUnsupportedError) {