From 9d42242ba087378fa43874e077a5d0c78d040084 Mon Sep 17 00:00:00 2001 From: Carlos Santos <4a.santos@gmail.com> Date: Mon, 21 Apr 2025 16:18:28 +0200 Subject: [PATCH] backend: Updated recording status when a starting timeout occurs --- backend/src/helpers/recording.helper.ts | 9 ++++++++- backend/src/services/livekit-webhook.service.ts | 8 +------- backend/src/services/recording.service.ts | 8 ++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/backend/src/helpers/recording.helper.ts b/backend/src/helpers/recording.helper.ts index 463b9ba..4d88d65 100644 --- a/backend/src/helpers/recording.helper.ts +++ b/backend/src/helpers/recording.helper.ts @@ -1,6 +1,7 @@ import { EgressInfo } from 'livekit-server-sdk'; import { MeetRecordingInfo, MeetRecordingStatus } from '@typings-ce'; import { EgressStatus } from '@livekit/protocol'; +import INTERNAL_CONFIG from '../config/internal-config.js'; export class RecordingHelper { private constructor() { @@ -29,7 +30,7 @@ export class RecordingHelper { size, errorCode: errorCode ? Number(errorCode) : undefined, error: error ? String(error) : undefined, - details: details ? String(details) : undefined, + details: details ? String(details) : undefined }; } @@ -174,6 +175,12 @@ export class RecordingHelper { return size !== 0 ? size : undefined; } + static buildMetadataFilePath(recordingId: string): string { + const { roomId, egressId, uid } = RecordingHelper.extractInfoFromRecordingId(recordingId); + + return `${INTERNAL_CONFIG.S3_RECORDINGS_PREFIX}/.metadata/${roomId}/${egressId}/${uid}.json`; + } + private static toSeconds(nanoseconds: number): number { const nanosecondsToSeconds = 1 / 1_000_000_000; return nanoseconds * nanosecondsToSeconds; diff --git a/backend/src/services/livekit-webhook.service.ts b/backend/src/services/livekit-webhook.service.ts index 10d3946..adbb53f 100644 --- a/backend/src/services/livekit-webhook.service.ts +++ b/backend/src/services/livekit-webhook.service.ts @@ -184,7 +184,7 @@ export class LivekitWebhookService { const recordingInfo: MeetRecordingInfo = RecordingHelper.toRecordingInfo(egressInfo); const { roomId, recordingId, status } = recordingInfo; - const metadataPath = this.buildMetadataFilePath(recordingId); + const metadataPath = RecordingHelper.buildMetadataFilePath(recordingId); this.logger.debug(`Recording '${recordingId}' status: '${status}'`); @@ -267,10 +267,4 @@ export class LivekitWebhookService { this.logger.error(`Error saving room secrets for room ${roomId}: ${error}`); } } - - protected buildMetadataFilePath(recordingId: string): string { - const { roomId, egressId, uid } = RecordingHelper.extractInfoFromRecordingId(recordingId); - - return `${INTERNAL_CONFIG.S3_RECORDINGS_PREFIX}/.metadata/${roomId}/${egressId}/${uid}.json`; - } } diff --git a/backend/src/services/recording.service.ts b/backend/src/services/recording.service.ts index aec39d0..ca533e3 100644 --- a/backend/src/services/recording.service.ts +++ b/backend/src/services/recording.service.ts @@ -498,6 +498,7 @@ export class RecordingService { let shouldReleaseLock = false; try { + await this.updateRecordingStatus(recordingId, MeetRecordingStatus.FAILED); await this.stopRecording(recordingId); // The recording was stopped successfully // the cleanup timer will be cancelled when the egress_ended event is received. @@ -598,6 +599,13 @@ export class RecordingService { } } + protected async updateRecordingStatus(recordingId: string, status: MeetRecordingStatus): Promise { + const metadataPath = RecordingHelper.buildMetadataFilePath(recordingId); + const recordingInfo = await this.getRecording(recordingId); + recordingInfo.status = status; + await this.s3Service.saveObject(metadataPath, recordingInfo); + } + /** * Cleans up orphaned recording locks in the system. *