✨(backend) notify participants only if the room exists
Improves sendData reliability by preventing execution when the room doesn’t exist. This change addresses errors in staging and production where waiting participants arrive before the room owner creates the room. In remote environments, the LiveKit Python SDK doesn’t return a clean Twirp error when the room is missing; instead of a proper "server unknown" response, it raises a ContentTypeError, as if the LiveKit server weren’t responding with a JSON payload, even though the code specifies otherwise. While the issue cannot be reproduced locally, this should help mitigate production errors. Part of a broader effort to enhance data transmission reliability. Importantly, a participant requesting entry to a room before the owner arrives should not be considered an exception.
This commit is contained in:
@@ -12,7 +12,12 @@ from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
|
||||
from asgiref.sync import async_to_sync
|
||||
from livekit.api import LiveKitAPI, SendDataRequest, TwirpError # pylint: disable=E0611
|
||||
from livekit.api import ( # pylint: disable=E0611
|
||||
ListRoomsRequest,
|
||||
LiveKitAPI,
|
||||
SendDataRequest,
|
||||
TwirpError,
|
||||
)
|
||||
|
||||
from core import models, utils
|
||||
|
||||
@@ -343,7 +348,18 @@ class LobbyService:
|
||||
}
|
||||
|
||||
lkapi = LiveKitAPI(**settings.LIVEKIT_CONFIGURATION)
|
||||
|
||||
try:
|
||||
room_response = await lkapi.room.list_rooms(
|
||||
ListRoomsRequest(
|
||||
names=[str(room_id)],
|
||||
)
|
||||
)
|
||||
|
||||
# Check if the room exists
|
||||
if not room_response.rooms:
|
||||
return
|
||||
|
||||
await lkapi.room.send_data(
|
||||
SendDataRequest(
|
||||
room=str(room_id),
|
||||
|
||||
Reference in New Issue
Block a user