backend: Add handling for room started event and refactor room finished webhook logic

This commit is contained in:
Carlos Santos 2025-05-05 17:43:25 +02:00
parent 4983729c1d
commit bbbb7fc0c1
5 changed files with 58 additions and 14 deletions

View File

@ -37,8 +37,11 @@ export const lkWebhookHandler = async (req: Request, res: Response) => {
case 'participant_joined':
await lkWebhookService.handleParticipantJoined(room!, participant!);
break;
case 'room_started':
await lkWebhookService.handleRoomStarted(room!);
break;
case 'room_finished':
await lkWebhookService.handleMeetingFinished(room!);
await lkWebhookService.handleRoomFinished(room!);
break;
default:
break;

View File

@ -139,6 +139,28 @@ export class LivekitWebhookService {
}
}
/**
* Handles a room started event from LiveKit.
*
* This method retrieves the corresponding meet room from the room service using the LiveKit room name.
* If the meet room is found, it sends a webhook notification indicating that the meeting has started.
* If the meet room is not found, it logs a warning message.
*/
async handleRoomStarted(room: Room) {
try {
const meetRoom = await this.roomService.getMeetRoom(room.name);
if (!meetRoom) {
this.logger.warn(`Room ${room.name} not found in OpenVidu Meet.`);
return;
}
await this.openViduWebhookService.sendMeetingStartedWebhook(meetRoom);
} catch (error) {
this.logger.error('Error sending meeting started webhook:', error);
}
}
/**
* Handles the event when a room is finished.
*
@ -148,12 +170,18 @@ export class LivekitWebhookService {
* @param {Room} room - The room object that has finished.
* @returns {Promise<void>} A promise that resolves when the webhook has been sent.
*/
async handleMeetingFinished(room: Room): Promise<void> {
async handleRoomFinished(room: Room): Promise<void> {
try {
const [meetRoom] = await Promise.all([
this.roomService.getMeetRoom(room.name),
const meetRoom = await this.roomService.getMeetRoom(room.name);
if (!meetRoom) {
this.logger.warn(`Room ${room.name} not found in OpenVidu Meet.`);
return;
}
await Promise.all([
this.recordingService.releaseRecordingLockIfNoEgress(room.name),
this.openViduWebhookService.sendRoomFinishedWebhook(room)
this.openViduWebhookService.sendMeetingEndedWebhook(meetRoom)
]);
if (meetRoom.markedForDeletion) {

View File

@ -1,5 +1,6 @@
import {
MeetRecordingInfo,
MeetRoom,
MeetWebhookEvent,
MeetWebhookEventType,
MeetWebhookPayload,
@ -7,7 +8,6 @@ import {
} from '@typings-ce';
import crypto from 'crypto';
import { inject, injectable } from 'inversify';
import { Room } from 'livekit-server-sdk';
import { MEET_API_KEY } from '../environment.js';
import { LoggerService, MeetStorageService } from './index.js';
@ -18,13 +18,20 @@ export class OpenViduWebhookService {
@inject(MeetStorageService) protected globalPrefService: MeetStorageService
) {}
// TODO: Implement Room webhooks
async sendRoomFinishedWebhook(room: Room) {
// try {
// await this.sendWebhookEvent(MeetWebhookEventType.ROOM_FINISHED, data);
// } catch (error) {
// this.logger.error(`Error sending room finished webhook: ${error}`);
// }
async sendMeetingStartedWebhook(room: MeetRoom) {
try {
await this.sendWebhookEvent(MeetWebhookEventType.MEETING_STARTED, room);
} catch (error) {
this.logger.error(`Error sending meeting started webhook: ${error}`);
}
}
async sendMeetingEndedWebhook(room: MeetRoom) {
try {
await this.sendWebhookEvent(MeetWebhookEventType.MEETING_ENDED, room);
} catch (error) {
this.logger.error(`Error sending meeting ended webhook: ${error}`);
}
}
async sendRecordingStartedWebhook(recordingInfo: MeetRecordingInfo) {

View File

@ -4,6 +4,8 @@ import { MeetRoom } from './room.js';
export type MeetWebhookPayload = MeetRecordingInfo | MeetRoom;
export const enum MeetWebhookEventType {
MEETING_STARTED = 'meetingStarted',
MEETING_ENDED = 'meetingEnded',
RECORDING_STARTED = 'recordingStarted',
RECORDING_UPDATED = 'recordingUpdated',
RECORDING_ENDED = 'recordingEnded',

View File

@ -1,7 +1,11 @@
#!/bin/sh
HEADER_KEY="THIS HEADER IS AUTOGENERATED. DO NOT MODIFY MANUALLY."
HEADER="/** $HEADER_KEY For any changes, please update the '/openvidu-meet/typings' directory. */"
HEADER="
/**
* $HEADER_KEY
* ! For any changes, please update the '/openvidu-meet/typings' directory.
**/"
SOURCE_DIR="src"
FRONTEND_DIR="../frontend/projects/shared-meet-components/src/lib/typings/ce"