backend: Add handling for room started event and refactor room finished webhook logic
This commit is contained in:
parent
4983729c1d
commit
bbbb7fc0c1
@ -37,8 +37,11 @@ export const lkWebhookHandler = async (req: Request, res: Response) => {
|
|||||||
case 'participant_joined':
|
case 'participant_joined':
|
||||||
await lkWebhookService.handleParticipantJoined(room!, participant!);
|
await lkWebhookService.handleParticipantJoined(room!, participant!);
|
||||||
break;
|
break;
|
||||||
|
case 'room_started':
|
||||||
|
await lkWebhookService.handleRoomStarted(room!);
|
||||||
|
break;
|
||||||
case 'room_finished':
|
case 'room_finished':
|
||||||
await lkWebhookService.handleMeetingFinished(room!);
|
await lkWebhookService.handleRoomFinished(room!);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -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.
|
* Handles the event when a room is finished.
|
||||||
*
|
*
|
||||||
@ -148,12 +170,18 @@ export class LivekitWebhookService {
|
|||||||
* @param {Room} room - The room object that has finished.
|
* @param {Room} room - The room object that has finished.
|
||||||
* @returns {Promise<void>} A promise that resolves when the webhook has been sent.
|
* @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 {
|
try {
|
||||||
const [meetRoom] = await Promise.all([
|
const meetRoom = await this.roomService.getMeetRoom(room.name);
|
||||||
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.recordingService.releaseRecordingLockIfNoEgress(room.name),
|
||||||
this.openViduWebhookService.sendRoomFinishedWebhook(room)
|
this.openViduWebhookService.sendMeetingEndedWebhook(meetRoom)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (meetRoom.markedForDeletion) {
|
if (meetRoom.markedForDeletion) {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
MeetRecordingInfo,
|
MeetRecordingInfo,
|
||||||
|
MeetRoom,
|
||||||
MeetWebhookEvent,
|
MeetWebhookEvent,
|
||||||
MeetWebhookEventType,
|
MeetWebhookEventType,
|
||||||
MeetWebhookPayload,
|
MeetWebhookPayload,
|
||||||
@ -7,7 +8,6 @@ import {
|
|||||||
} from '@typings-ce';
|
} from '@typings-ce';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import { inject, injectable } from 'inversify';
|
import { inject, injectable } from 'inversify';
|
||||||
import { Room } from 'livekit-server-sdk';
|
|
||||||
import { MEET_API_KEY } from '../environment.js';
|
import { MEET_API_KEY } from '../environment.js';
|
||||||
import { LoggerService, MeetStorageService } from './index.js';
|
import { LoggerService, MeetStorageService } from './index.js';
|
||||||
|
|
||||||
@ -18,13 +18,20 @@ export class OpenViduWebhookService {
|
|||||||
@inject(MeetStorageService) protected globalPrefService: MeetStorageService
|
@inject(MeetStorageService) protected globalPrefService: MeetStorageService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
// TODO: Implement Room webhooks
|
async sendMeetingStartedWebhook(room: MeetRoom) {
|
||||||
async sendRoomFinishedWebhook(room: Room) {
|
try {
|
||||||
// try {
|
await this.sendWebhookEvent(MeetWebhookEventType.MEETING_STARTED, room);
|
||||||
// await this.sendWebhookEvent(MeetWebhookEventType.ROOM_FINISHED, data);
|
} catch (error) {
|
||||||
// } catch (error) {
|
this.logger.error(`Error sending meeting started webhook: ${error}`);
|
||||||
// this.logger.error(`Error sending room finished 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) {
|
async sendRecordingStartedWebhook(recordingInfo: MeetRecordingInfo) {
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import { MeetRoom } from './room.js';
|
|||||||
export type MeetWebhookPayload = MeetRecordingInfo | MeetRoom;
|
export type MeetWebhookPayload = MeetRecordingInfo | MeetRoom;
|
||||||
|
|
||||||
export const enum MeetWebhookEventType {
|
export const enum MeetWebhookEventType {
|
||||||
|
MEETING_STARTED = 'meetingStarted',
|
||||||
|
MEETING_ENDED = 'meetingEnded',
|
||||||
RECORDING_STARTED = 'recordingStarted',
|
RECORDING_STARTED = 'recordingStarted',
|
||||||
RECORDING_UPDATED = 'recordingUpdated',
|
RECORDING_UPDATED = 'recordingUpdated',
|
||||||
RECORDING_ENDED = 'recordingEnded',
|
RECORDING_ENDED = 'recordingEnded',
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
HEADER_KEY="THIS HEADER IS AUTOGENERATED. DO NOT MODIFY MANUALLY."
|
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"
|
SOURCE_DIR="src"
|
||||||
|
|
||||||
FRONTEND_DIR="../frontend/projects/shared-meet-components/src/lib/typings/ce"
|
FRONTEND_DIR="../frontend/projects/shared-meet-components/src/lib/typings/ce"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user