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.
This commit is contained in:
2024-12-05 19:35:17 +07:00
parent 7699a07d1d
commit 9d64a199e2
4 changed files with 62 additions and 30 deletions

View File

@@ -1,7 +1,7 @@
import { Module, Global } from '@nestjs/common' import { Module, Global } from '@nestjs/common'
import { LiveKitService } from './livekit.service' import { LiveKitService } from './livekit.service'
import { LiveKitRoomService } from './livekit.room.service' import { LiveKitRoomService } from './livekit.room.service'
import { LiveKitEgressService } from './livekit.egress' import { LiveKitEgressService } from './livekit.egress.service'
@Global() @Global()
@Module({ @Module({
providers: [LiveKitService, LiveKitRoomService, LiveKitEgressService], providers: [LiveKitService, LiveKitRoomService, LiveKitEgressService],

View File

@@ -1,7 +1,17 @@
import { Injectable } from '@nestjs/common' import { Injectable } from '@nestjs/common'
// @ts-expect-error import {
import { Room, RoomServiceClient, RoomEgress } from 'livekit-server-sdk' Room,
import { LiveKitEgressService } from './livekit.egress' 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' import { DateTimeUtils } from 'src/common/utils/datetime.utils'
@Injectable() @Injectable()
@@ -27,21 +37,32 @@ export class LiveKitRoomService {
name: roomId, name: roomId,
maxParticipants: 2, maxParticipants: 2,
egress: new RoomEgress({ egress: new RoomEgress({
tracks: { room: new RoomCompositeEgressRequest({
output: { layout: 'grid',
case: 's3', options: {
value: { case: 'preset',
bucket: 'objects', value: EncodingOptionsPreset.H264_1080P_60,
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()}`, 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 return room
} }
@@ -51,19 +72,31 @@ export class LiveKitRoomService {
name: roomId, name: roomId,
maxParticipants, maxParticipants,
egress: new RoomEgress({ egress: new RoomEgress({
tracks: { room: new RoomCompositeEgressRequest({
output: { layout: 'spotlight',
case: 's3', options: {
value: { case: 'preset',
bucket: 'objects', value: EncodingOptionsPreset.H264_1080P_60,
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()}`, 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 return room

View File

@@ -10,7 +10,6 @@
"sourceMap": true, "sourceMap": true,
"outDir": "./dist", "outDir": "./dist",
"baseUrl": "./", "baseUrl": "./",
"rootDir": "./src",
"incremental": true, "incremental": true,
"skipLibCheck": true, "skipLibCheck": true,
"strictNullChecks": true, "strictNullChecks": true,