backend: Refactor Livekit webhook handling to remove OpenVidu dependency and add room finished event handling

This commit is contained in:
Carlos Santos 2025-03-14 20:06:42 +01:00
parent 9f0877780e
commit ca56521604
2 changed files with 19 additions and 3 deletions

View File

@ -2,7 +2,6 @@ import { Request, Response } from 'express';
import { LoggerService } from '../services/logger.service.js';
import { LivekitWebhookService } from '../services/livekit-webhook.service.js';
import { WebhookEvent } from 'livekit-server-sdk';
import { OpenViduWebhookService } from '../services/openvidu-webhook.service.js';
import { container } from '../config/dependency-injector.config.js';
export const lkWebhookHandler = async (req: Request, res: Response) => {
@ -10,7 +9,6 @@ export const lkWebhookHandler = async (req: Request, res: Response) => {
try {
const lkWebhookService = container.get(LivekitWebhookService);
const ovWebhookService = container.get(OpenViduWebhookService);
const webhookEvent: WebhookEvent = await lkWebhookService.getEventFromWebhook(
req.body,
@ -39,7 +37,7 @@ export const lkWebhookHandler = async (req: Request, res: Response) => {
await lkWebhookService.handleParticipantJoined(room!, participant!);
break;
case 'room_finished':
await ovWebhookService.sendRoomFinishedWebhook(room!);
await lkWebhookService.handleRoomFinished(room!);
break;
default:
break;

View File

@ -160,6 +160,24 @@ export class LivekitWebhookService {
}
}
/**
* Handles the event when a room is finished.
*
* This method sends a webhook notification indicating that the room has finished.
* If an error occurs while sending the webhook, it logs the error.
*
* @param {Room} room - The room object that has finished.
* @returns {Promise<void>} A promise that resolves when the webhook has been sent.
*/
async handleRoomFinished(room: Room) {
try {
await this.openViduWebhookService.sendRoomFinishedWebhook(room);
} catch (error) {
this.logger.error(`Error handling room finished event: ${error}`);
}
}
private async sendStatusSignal(roomName: string, roomId: string, participantSid: string) {
// Get recording list
const recordingInfo = await this.recordingService.getAllRecordingsByRoom(roomName, roomId);