From 9d64a199e2dff1ec52442a684f882b96ca568629 Mon Sep 17 00:00:00 2001 From: Ly Tuan Kiet Date: Thu, 5 Dec 2024 19:35:17 +0700 Subject: [PATCH] refactor: update LiveKit egress service and module structure - Removed the `livekit.egress.ts` file and replaced it with `livekit.egress.service.ts` for better clarity and consistency in naming. - Updated `livekit.module.ts` to reflect the new import path for the `LiveKitEgressService`. - Enhanced `livekit.room.service.ts` to utilize the new egress service structure, including improved egress configuration for recording sessions with dynamic file output settings. - Removed the `rootDir` property from `tsconfig.json` to streamline the TypeScript configuration. --- ...it.egress.ts => livekit.egress.service.ts} | 0 src/LiveKit/livekit.module.ts | 2 +- src/LiveKit/livekit.room.service.ts | 89 +++++++++++++------ tsconfig.json | 1 - 4 files changed, 62 insertions(+), 30 deletions(-) rename src/LiveKit/{livekit.egress.ts => livekit.egress.service.ts} (100%) diff --git a/src/LiveKit/livekit.egress.ts b/src/LiveKit/livekit.egress.service.ts similarity index 100% rename from src/LiveKit/livekit.egress.ts rename to src/LiveKit/livekit.egress.service.ts diff --git a/src/LiveKit/livekit.module.ts b/src/LiveKit/livekit.module.ts index 455345a..0eac863 100644 --- a/src/LiveKit/livekit.module.ts +++ b/src/LiveKit/livekit.module.ts @@ -1,7 +1,7 @@ import { Module, Global } from '@nestjs/common' import { LiveKitService } from './livekit.service' import { LiveKitRoomService } from './livekit.room.service' -import { LiveKitEgressService } from './livekit.egress' +import { LiveKitEgressService } from './livekit.egress.service' @Global() @Module({ providers: [LiveKitService, LiveKitRoomService, LiveKitEgressService], diff --git a/src/LiveKit/livekit.room.service.ts b/src/LiveKit/livekit.room.service.ts index 4a207c9..2cd79c6 100644 --- a/src/LiveKit/livekit.room.service.ts +++ b/src/LiveKit/livekit.room.service.ts @@ -1,7 +1,17 @@ import { Injectable } from '@nestjs/common' -// @ts-expect-error -import { Room, RoomServiceClient, RoomEgress } from 'livekit-server-sdk' -import { LiveKitEgressService } from './livekit.egress' +import { + Room, + RoomServiceClient, + RoomEgress, + AutoTrackEgress, + AutoParticipantEgress, + EncodedFileType, + EncodedFileOutput, + RoomCompositeEgressRequest, + EncodingOptionsPreset, + // @ts-expect-error +} from 'livekit-server-sdk' +import { LiveKitEgressService } from './livekit.egress.service' import { DateTimeUtils } from 'src/common/utils/datetime.utils' @Injectable() @@ -27,21 +37,32 @@ export class LiveKitRoomService { name: roomId, maxParticipants: 2, egress: new RoomEgress({ - tracks: { - output: { - case: 's3', - value: { - bucket: 'objects', - accessKey: process.env.MINIO_ACCESS_KEY, - secret: process.env.MINIO_SECRET_KEY, - endpoint: process.env.BASE_URL, - region: process.env.MINIO_REGION, - }, + room: new RoomCompositeEgressRequest({ + layout: 'grid', + options: { + case: 'preset', + value: EncodingOptionsPreset.H264_1080P_60, }, - filepath: `epess/records/${roomId}/${roomId}-${DateTimeUtils.now().toISO()}`, - }, + audioOnly: false, + videoOnly: false, + fileOutputs: [ + { + fileType: EncodedFileType.MP4, + filepath: `epess/records/${roomId}/${roomId}-${DateTimeUtils.now().toISO()}`, + output: { + case: 's3', + value: { + bucket: 'objects', + accessKey: process.env.MINIO_ACCESS_KEY, + secret: process.env.MINIO_SECRET_KEY, + endpoint: process.env.BASE_URL, + region: process.env.MINIO_REGION, + }, + }, + }, + ], + }), }), - departureTimeout: 1000 * 60 * 10, // 10 minutes }) return room } @@ -51,19 +72,31 @@ export class LiveKitRoomService { name: roomId, maxParticipants, egress: new RoomEgress({ - tracks: { - output: { - case: 's3', - value: { - bucket: 'objects', - accessKey: process.env.MINIO_ACCESS_KEY, - secret: process.env.MINIO_SECRET_KEY, - endpoint: process.env.BASE_URL, - region: process.env.MINIO_REGION, - }, + room: new RoomCompositeEgressRequest({ + layout: 'spotlight', + options: { + case: 'preset', + value: EncodingOptionsPreset.H264_1080P_60, }, - filepath: `epess/records/${roomId}/${roomId}-${DateTimeUtils.now().toISO()}`, - }, + audioOnly: false, + videoOnly: false, + fileOutputs: [ + { + fileType: EncodedFileType.MP4, + output: { + case: 's3', + value: { + bucket: 'objects', + accessKey: process.env.MINIO_ACCESS_KEY, + secret: process.env.MINIO_SECRET_KEY, + endpoint: process.env.BASE_URL, + region: process.env.MINIO_REGION, + }, + }, + filepath: `epess/records/${roomId}/${roomId}-${DateTimeUtils.now().toISO()}`, + }, + ], + }), }), }) return room diff --git a/tsconfig.json b/tsconfig.json index 956221d..51de306 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,6 @@ "sourceMap": true, "outDir": "./dist", "baseUrl": "./", - "rootDir": "./src", "incremental": true, "skipLibCheck": true, "strictNullChecks": true,