backend: Add error handling for starting recordings when no participants are present

This commit is contained in:
Carlos Santos 2025-04-07 19:33:38 +02:00
parent 30ee4dfbca
commit a17bcd5771
2 changed files with 10 additions and 0 deletions

View File

@ -75,6 +75,10 @@ export const errorRecordingAlreadyStarted = (roomId: string): OpenViduMeetError
return new OpenViduMeetError('Recording Error', `The room '${roomId}' is already being recorded`, 409);
};
export const errorRoomHasNoParticipants = (roomId: string): OpenViduMeetError => {
return new OpenViduMeetError('Recording Error', `The room '${roomId}' has no participants`, 409);
};
const isMatchingError = (error: OpenViduMeetError, originalError: OpenViduMeetError): boolean => {
return (
error instanceof OpenViduMeetError &&

View File

@ -9,6 +9,7 @@ import {
errorRecordingCannotBeStoppedWhileStarting,
errorRecordingNotFound,
errorRecordingNotStopped,
errorRoomHasNoParticipants,
errorRoomNotFound,
internalError,
isErrorRecordingAlreadyStopped,
@ -68,6 +69,11 @@ export class RecordingService {
//TODO: Check if the room has participants before starting the recording
//room.numParticipants === 0 ? throw errorNoParticipants(roomId);
const lkRoom = await this.livekitService.getRoom(roomId);
if (!lkRoom) throw errorRoomNotFound(roomId);
if (lkRoom.numParticipants === 0) throw errorRoomHasNoParticipants(roomId);
// Attempt to acquire lock. If the lock is not acquired, the recording is already active.
acquiredLock = await this.acquireRoomRecordingActiveLock(roomId);