feat: add room egress functionality to LiveKitRoomService

- Introduced RoomEgress to enable recording of meeting rooms with S3 storage configuration.
- Updated createServiceMeetingRoom method to include egress settings for room recording.
- Enhanced integration with LiveKit by allowing dynamic file path generation for recordings.
This commit is contained in:
2024-12-03 17:42:18 +07:00
parent a6c511a2de
commit 81e6192974

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common' import { Injectable } from '@nestjs/common'
// @ts-expect-error // @ts-expect-error
import { Room, RoomServiceClient } from 'livekit-server-sdk' import { Room, RoomServiceClient, RoomEgress } from 'livekit-server-sdk'
import { LiveKitEgressService } from './livekit.egress' import { LiveKitEgressService } from './livekit.egress'
@Injectable() @Injectable()
@@ -10,15 +10,28 @@ export class LiveKitRoomService {
process.env.LIVEKIT_API_KEY as string, process.env.LIVEKIT_API_KEY as string,
process.env.LIVEKIT_API_SECRET as string, process.env.LIVEKIT_API_SECRET as string,
) )
private readonly roomEgress = new RoomEgress({
tracks: {
output: {
case: 's3',
value: {
bucket: process.env.RECORDING_BUCKET_NAME as string,
accessKey: process.env.MINIO_ACCESS_KEY as string,
secret: process.env.MINIO_SECRET_KEY as string,
endpoint: process.env.MINIO_ENDPOINT as string,
},
},
filepath: '${roomName}/${roomName}-${start_time}',
},
})
constructor(private readonly egressService: LiveKitEgressService) {} constructor(private readonly egressService: LiveKitEgressService) {}
async createServiceMeetingRoom(roomId: string) { async createServiceMeetingRoom(roomId: string) {
const room = await this.roomServiceClient.createRoom({ const room = await this.roomServiceClient.createRoom({
name: roomId, name: roomId,
maxParticipants: 2, maxParticipants: 2,
egress: this.roomEgress,
}) })
// start recording
await this.egressService.startRecording(roomId)
return room return room
} }