refactor: update LiveKit integration and clean up unused services
- Changed the base image in Dockerfile to use a lighter node:alpine version. - Removed unused dependencies from package-lock.json and package.json, including @turbodocx/html-to-docx and jsdom. - Simplified LiveKit module by removing unnecessary services (LiveKitParticipantService, LiveKitRoomService) and adjusting related schemas and services for better maintainability. - Updated CollaborationSessionSchema to streamline access token creation and room management. - Commented out unused imports and services in various modules to enhance code clarity and reduce complexity.
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { Module, Global } from '@nestjs/common'
|
||||
import { LiveKitService } from './livekit.service'
|
||||
import { LiveKitParticipantService } from './livekit.participant.service'
|
||||
import { LiveKitRoomService } from './livekit.room.service'
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [LiveKitService, LiveKitParticipantService, LiveKitRoomService],
|
||||
providers: [LiveKitService],
|
||||
exports: [LiveKitService],
|
||||
})
|
||||
export class LiveKitModule {}
|
||||
|
||||
@@ -1,20 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
// @ts-ignore
|
||||
import { AccessToken } from 'livekit-server-sdk'
|
||||
// @ts-expect-error
|
||||
import { ParticipantPermission, RoomServiceClient } from 'livekit-server-sdk'
|
||||
|
||||
@Injectable()
|
||||
export class LiveKitParticipantService {
|
||||
async createAccessToken(participantId: string) {
|
||||
return new AccessToken(process.env.LIVEKIT_API_KEY as string, process.env.LIVEKIT_API_SECRET as string, {
|
||||
identity: participantId,
|
||||
})
|
||||
}
|
||||
|
||||
async grantRoomJoinPermission(token: AccessToken, roomName: string) {
|
||||
token.addGrant({ roomJoin: true, room: roomName })
|
||||
}
|
||||
|
||||
async toJWT(token: AccessToken) {
|
||||
return token.toJwt()
|
||||
}
|
||||
constructor(private readonly roomServiceClient: RoomServiceClient) {}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,26 @@
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { forwardRef, Injectable } from '@nestjs/common'
|
||||
// @ts-expect-error
|
||||
import { Room, RoomServiceClient } from 'livekit-server-sdk'
|
||||
|
||||
@Injectable()
|
||||
export class LiveKitRoomService {
|
||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||
private roomServiceClient: any
|
||||
constructor() {
|
||||
this.initializeRoomServiceClient()
|
||||
}
|
||||
constructor(private readonly roomServiceClient: RoomServiceClient) {}
|
||||
|
||||
private async initializeRoomServiceClient() {
|
||||
const { RoomServiceClient } = await import('livekit-server-sdk')
|
||||
this.roomServiceClient = new RoomServiceClient(
|
||||
process.env.LIVEKIT_URL as string,
|
||||
process.env.LIVEKIT_API_KEY as string,
|
||||
process.env.LIVEKIT_API_SECRET as string,
|
||||
)
|
||||
}
|
||||
|
||||
async createServiceMeetingRoom(chattingRoomId: string) {
|
||||
async createServiceMeetingRoom(roomId: string) {
|
||||
const room = await this.roomServiceClient.createRoom({
|
||||
maxParticipants: 3,
|
||||
name: chattingRoomId,
|
||||
name: roomId,
|
||||
maxParticipants: 2,
|
||||
})
|
||||
|
||||
return room
|
||||
}
|
||||
|
||||
async createWorkshopMeetingRoom(workshopId: string, maxParticipants: number) {
|
||||
async createWorkshopRoom(roomId: string, maxParticipants: number) {
|
||||
const room = await this.roomServiceClient.createRoom({
|
||||
maxParticipants: maxParticipants,
|
||||
name: workshopId,
|
||||
name: roomId,
|
||||
maxParticipants,
|
||||
})
|
||||
return room
|
||||
}
|
||||
}
|
||||
|
||||
export const roomServiceClient = forwardRef(() => LiveKitRoomService)
|
||||
|
||||
@@ -1,15 +1,26 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { LiveKitRoomService } from './livekit.room.service'
|
||||
import { LiveKitParticipantService } from './livekit.participant.service'
|
||||
import { User } from '@prisma/client'
|
||||
import { Injectable, Logger } from '@nestjs/common'
|
||||
// @ts-expect-error
|
||||
import { RoomServiceClient, AccessToken } from 'livekit-server-sdk'
|
||||
|
||||
@Injectable()
|
||||
export class LiveKitService {
|
||||
constructor(
|
||||
private liveKitRoomService: LiveKitRoomService,
|
||||
private liveKitParticipantService: LiveKitParticipantService,
|
||||
) {}
|
||||
constructor() {}
|
||||
|
||||
async createAccessToken(participantId: string) {
|
||||
return await this.liveKitParticipantService.createAccessToken(participantId)
|
||||
async createToken(me: User, roomName: string) {
|
||||
if (!process.env.LIVEKIT_API_KEY || !process.env.LIVEKIT_API_SECRET) {
|
||||
throw new Error('LIVEKIT_API_KEY and LIVEKIT_API_SECRET must be set')
|
||||
}
|
||||
if (!me.name) {
|
||||
throw new Error('User must have a name')
|
||||
}
|
||||
const token = new AccessToken(process.env.LIVEKIT_API_KEY as string, process.env.LIVEKIT_API_SECRET as string, {
|
||||
identity: me.name,
|
||||
})
|
||||
token.addGrant({
|
||||
roomJoin: true,
|
||||
room: roomName,
|
||||
})
|
||||
return await token.toJwt()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// @ts-ignore
|
||||
import { TrackInfo } from 'livekit-server-sdk'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
export class LiveKitTrackService {
|
||||
}
|
||||
@Injectable()
|
||||
export class LiveKitTrackService {}
|
||||
|
||||
Reference in New Issue
Block a user