♻️(backend) refactor backend recording state management
Instead of relying on the egress_started event—which fires when egress is starting, not actually started—I now rely on egress_updated for more accurate status updates. This is especially important for the active status, which triggers after egress has truly joined the room. Using this avoids prematurely stopping client-side listening to room.isRecording updates. A further refactoring may remove reliance on room updates entirely. The goal is to minimize handling metadata in the mediator class. egress_starting is still used for simplicity, but egress_started could be considered in the future. Note: if the API to start egress hasn’t responded yet, the webhook may fail to find the recording because it currently matches by worker ID. This is unstable. A better approach would be to pass the database ID in the egress metadata and recover the recording from it in the webhook.
This commit is contained in:
committed by
aleb_the_flash
parent
2863aa832d
commit
f6cdb1125b
@@ -138,23 +138,19 @@ class LiveKitEventsService:
|
||||
# pylint: disable=not-callable
|
||||
handler(data)
|
||||
|
||||
def _handle_egress_started(self, data):
|
||||
"""Handle 'egress_started' event."""
|
||||
def _handle_egress_updated(self, data):
|
||||
"""Handle 'egress_updated' event."""
|
||||
|
||||
egress_id = data.egress_info.egress_id
|
||||
try:
|
||||
recording = models.Recording.objects.get(
|
||||
worker_id=data.egress_info.egress_id
|
||||
)
|
||||
recording = models.Recording.objects.get(worker_id=egress_id)
|
||||
except models.Recording.DoesNotExist as err:
|
||||
raise ActionFailedError(
|
||||
f"Recording with worker ID {data.egress_info.egress_id} does not exist"
|
||||
f"Recording with worker ID {egress_id} does not exist"
|
||||
) from err
|
||||
|
||||
try:
|
||||
room_name = str(recording.room.id)
|
||||
utils.update_room_metadata(room_name, {"recording_status": "started"})
|
||||
except utils.MetadataUpdateException as e:
|
||||
logger.exception("Failed to update room's metadata: %s", e)
|
||||
egress_status = data.egress_info.status
|
||||
self.recording_events.handle_update(recording, egress_status)
|
||||
|
||||
def _handle_egress_ended(self, data):
|
||||
"""Handle 'egress_ended' event."""
|
||||
|
||||
Reference in New Issue
Block a user