openvidu-recording-improved: Check if room is active before sending data message when recording is deleted

This commit is contained in:
juancarmore 2024-09-17 17:17:15 +02:00
parent 44f0c4fb81
commit ea89874179
4 changed files with 14 additions and 4 deletions

View File

@ -110,7 +110,12 @@ recordingController.delete("/:recordingName", async (req, res) => {
await recordingService.deleteRecording(recordingName); await recordingService.deleteRecording(recordingName);
// Notify to all participants that the recording was deleted // Notify to all participants that the recording was deleted
await roomService.sendDataToRoom(roomName, { recordingName }); const existsRoom = await roomService.exists(roomName);
if (existsRoom) {
await roomService.sendDataToRoom(roomName, { recordingName });
}
res.json({ message: "Recording deleted" }); res.json({ message: "Recording deleted" });
} catch (error) { } catch (error) {
console.error("Error deleting recording.", error); console.error("Error deleting recording.", error);

View File

@ -31,9 +31,9 @@ roomController.post("/", async (req, res) => {
try { try {
// Create room if it doesn't exist // Create room if it doesn't exist
const room = await roomService.getRoom(roomName); const exists = await roomService.exists(roomName);
if (!room) { if (!exists) {
await roomService.createRoom(roomName); await roomService.createRoom(roomName);
} }
} catch (error) { } catch (error) {

View File

@ -80,7 +80,7 @@ export class RecordingService {
} }
async deleteRecording(recordingName) { async deleteRecording(recordingName) {
const recordingKey = RECORDINGS_PATH + recordingName; const recordingKey = this.getRecordingKey(recordingName);
const metadataKey = this.getMetadataKey(recordingName); const metadataKey = this.getMetadataKey(recordingName);
// Delete the recording file and metadata file from S3 // Delete the recording file and metadata file from S3
await Promise.all([s3Service.deleteObject(recordingKey), s3Service.deleteObject(metadataKey)]); await Promise.all([s3Service.deleteObject(recordingKey), s3Service.deleteObject(metadataKey)]);

View File

@ -32,6 +32,11 @@ export class RoomService {
return rooms.length > 0 ? rooms[0] : null; return rooms.length > 0 ? rooms[0] : null;
} }
async exists(roomName) {
const room = await this.getRoom(roomName);
return room !== null;
}
async updateRoomMetadata(roomName, recordingStatus) { async updateRoomMetadata(roomName, recordingStatus) {
const metadata = { const metadata = {
createdBy: APP_NAME, createdBy: APP_NAME,