(backend) update a room's attributes from the external API

Update a room's access level and/or configuration using PATCH from the
external API. Log modifications and send to analytics.
This commit is contained in:
leo
2026-09-02 18:38:06 +02:00
parent cf3960db95
commit 9d6ed7aa21
15 changed files with 926 additions and 95 deletions
+33 -2
View File
@@ -30,9 +30,10 @@ class RoomNotFoundException(RoomManagementException):
class RoomManagement:
"""Service for managing LiveKit rooms."""
@classmethod
@async_to_sync
async def update_metadata(
self,
cls,
room_name: str,
metadata: Optional[Dict] = None,
remove_keys: Optional[list[str]] = None,
@@ -90,8 +91,9 @@ class RoomManagement:
finally:
await lkapi.aclose()
@classmethod
@async_to_sync
async def delete_room(self, room_name: str):
async def delete_room(cls, room_name: str):
"""Delete a LiveKit room and disconnect all participants.
Raises:
@@ -116,3 +118,32 @@ class RoomManagement:
raise RoomManagementException("Could not delete room") from e
finally:
await lkapi.aclose()
@classmethod
def sync_room_metadata(cls, room):
"""Push a room's configuration and access level to its LiveKit room metadata.
Failures are swallowed: a room that is not live yet, or a LiveKit hiccup,
should never fail the request that triggered the update.
"""
metadata = {
"configuration": room.configuration,
"access_level": room.access_level,
}
try:
cls.update_metadata(
room_name=str(room.id),
metadata=metadata,
)
except RoomNotFoundException:
logger.info(
"LiveKit room %s does not exist yet, skipping metadata sync",
room.id,
)
except RoomManagementException:
logger.warning(
"Failed to sync metadata to LiveKit for room %s",
room.id,
)