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,4 +1,4 @@
|
|||||||
FROM node:20 AS node_base
|
FROM node:alpine AS node_base
|
||||||
|
|
||||||
# Set the working directory
|
# Set the working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
2957
package-lock.json
generated
2957
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@@ -66,7 +66,6 @@
|
|||||||
"@prisma/client": "^5.21.1",
|
"@prisma/client": "^5.21.1",
|
||||||
"@smatch-corp/nestjs-pothos": "^0.3.0",
|
"@smatch-corp/nestjs-pothos": "^0.3.0",
|
||||||
"@smatch-corp/nestjs-pothos-apollo-driver": "^0.1.0",
|
"@smatch-corp/nestjs-pothos-apollo-driver": "^0.1.0",
|
||||||
"@turbodocx/html-to-docx": "^1.10.0",
|
|
||||||
"apollo-server-express": "^3.13.0",
|
"apollo-server-express": "^3.13.0",
|
||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
@@ -81,7 +80,6 @@
|
|||||||
"graphql-upload": "15.0.2",
|
"graphql-upload": "15.0.2",
|
||||||
"graphql-ws": "^5.16.0",
|
"graphql-ws": "^5.16.0",
|
||||||
"ioredis": "^5.4.1",
|
"ioredis": "^5.4.1",
|
||||||
"jsdom": "^25.0.1",
|
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"livekit-server-sdk": "^2.7.3",
|
"livekit-server-sdk": "^2.7.3",
|
||||||
"luxon": "^3.5.0",
|
"luxon": "^3.5.0",
|
||||||
@@ -94,24 +92,22 @@
|
|||||||
"reflect-metadata": "^0.2.0",
|
"reflect-metadata": "^0.2.0",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
"swagger-ui-express": "^5.0.1",
|
"swagger-ui-express": "^5.0.1",
|
||||||
|
"tsimportlib": "^0.0.5",
|
||||||
"type-graphql": "^2.0.0-rc.2",
|
"type-graphql": "^2.0.0-rc.2",
|
||||||
"yjs": "^13.6.20",
|
"yjs": "^13.6.20",
|
||||||
"zod": "^3.23.8"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "1.9.4",
|
"@biomejs/biome": "^1.9.4",
|
||||||
"@clerk/types": "^4.23.0",
|
"@clerk/types": "^4.23.0",
|
||||||
"@eslint/eslintrc": "^3.1.0",
|
|
||||||
"@eslint/js": "^9.12.0",
|
|
||||||
"@faker-js/faker": "^9.0.3",
|
"@faker-js/faker": "^9.0.3",
|
||||||
"@graphql-codegen/cli": "^5.0.2",
|
"@graphql-codegen/cli": "^5.0.2",
|
||||||
"@graphql-codegen/client-preset": "^4.4.0",
|
"@graphql-codegen/client-preset": "^4.4.0",
|
||||||
"@graphql-codegen/typescript": "4.0.9",
|
"@graphql-codegen/typescript": "4.0.9",
|
||||||
"@graphql-codegen/typescript-resolvers": "4.2.1",
|
"@graphql-codegen/typescript-resolvers": "4.2.1",
|
||||||
"@nestjs/cli": "^10.0.0",
|
"@nestjs/cli": "^10.4.8",
|
||||||
"@nestjs/schematics": "^10.0.0",
|
"@nestjs/schematics": "^10.2.3",
|
||||||
"@nestjs/testing": "^10.0.0",
|
"@nestjs/testing": "^10.4.12",
|
||||||
"@stylistic/eslint-plugin-js": "^2.9.0",
|
|
||||||
"@swc/cli": "^0.5.1",
|
"@swc/cli": "^0.5.1",
|
||||||
"@swc/core": "^1.9.3",
|
"@swc/core": "^1.9.3",
|
||||||
"@types/bcryptjs": "^2.4.6",
|
"@types/bcryptjs": "^2.4.6",
|
||||||
@@ -125,11 +121,6 @@
|
|||||||
"@types/supertest": "^6.0.0",
|
"@types/supertest": "^6.0.0",
|
||||||
"@types/uuid": "^10.0.0",
|
"@types/uuid": "^10.0.0",
|
||||||
"@types/ws": "^8.5.12",
|
"@types/ws": "^8.5.12",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
||||||
"@typescript-eslint/parser": "^8.0.0",
|
|
||||||
"eslint": "9.11.1",
|
|
||||||
"eslint-config-prettier": "^9.0.0",
|
|
||||||
"eslint-plugin-prettier": "^5.0.0",
|
|
||||||
"globals": "^15.10.0",
|
"globals": "^15.10.0",
|
||||||
"jest": "^29.5.0",
|
"jest": "^29.5.0",
|
||||||
"prettier": "^3.0.0",
|
"prettier": "^3.0.0",
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ import { Module } from '@nestjs/common'
|
|||||||
import { CollaborationSessionSchema } from './collaborationsession.schema'
|
import { CollaborationSessionSchema } from './collaborationsession.schema'
|
||||||
import { LiveKitModule } from 'src/LiveKit/livekit.module'
|
import { LiveKitModule } from 'src/LiveKit/livekit.module'
|
||||||
import { LiveKitService } from 'src/LiveKit/livekit.service'
|
import { LiveKitService } from 'src/LiveKit/livekit.service'
|
||||||
import { LiveKitParticipantService } from 'src/LiveKit/livekit.participant.service'
|
|
||||||
import { LiveKitRoomService } from 'src/LiveKit/livekit.room.service'
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [LiveKitModule],
|
imports: [LiveKitModule],
|
||||||
providers: [CollaborationSessionSchema, LiveKitService, LiveKitParticipantService, LiveKitRoomService],
|
providers: [CollaborationSessionSchema, LiveKitService],
|
||||||
exports: [CollaborationSessionSchema],
|
exports: [CollaborationSessionSchema],
|
||||||
})
|
})
|
||||||
export class CollaborationSessionModule {}
|
export class CollaborationSessionModule {}
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
import { Inject, Injectable, Logger } from '@nestjs/common'
|
import { Inject, Injectable, Logger } from '@nestjs/common'
|
||||||
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
||||||
import { Builder, SchemaContext } from '../Graphql/graphql.builder'
|
|
||||||
import { PrismaService } from '../Prisma/prisma.service'
|
|
||||||
// import { LiveKitRoomService } from 'src/LiveKit/livekit.room.service'
|
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
|
||||||
import { CollaborationSession, Role, ScheduleDateStatus } from '@prisma/client'
|
import { CollaborationSession, Role, ScheduleDateStatus } from '@prisma/client'
|
||||||
|
|
||||||
|
import { Builder, SchemaContext } from 'src/Graphql/graphql.builder'
|
||||||
|
import { PrismaService } from 'src/Prisma/prisma.service'
|
||||||
import { DateTimeUtils } from 'src/common/utils/datetime.utils'
|
import { DateTimeUtils } from 'src/common/utils/datetime.utils'
|
||||||
import { LiveKitService } from 'src/LiveKit/livekit.service'
|
import { LiveKitService } from 'src/LiveKit/livekit.service'
|
||||||
import { LiveKitParticipantService } from 'src/LiveKit/livekit.participant.service'
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CollaborationSessionSchema extends PothosSchema {
|
export class CollaborationSessionSchema extends PothosSchema {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||||
private readonly prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private readonly liveKitService: LiveKitService,
|
private readonly liveKitService: LiveKitService,
|
||||||
private readonly liveKitParticipantService: LiveKitParticipantService,
|
|
||||||
) {
|
) {
|
||||||
super()
|
super()
|
||||||
}
|
}
|
||||||
@@ -204,9 +201,8 @@ export class CollaborationSessionSchema extends PothosSchema {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (!meetingRoom) throw new Error('Meeting room not found')
|
if (!meetingRoom) throw new Error('Meeting room not found')
|
||||||
const token = await this.liveKitService.createAccessToken(ctx.http.me.id)
|
const token = await this.liveKitService.createToken(ctx.http.me, meetingRoom.id)
|
||||||
await this.liveKitParticipantService.grantRoomJoinPermission(token, meetingRoom.collaborationSessionId)
|
return token
|
||||||
return await this.liveKitParticipantService.toJWT(token)
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ import { Module } from '@nestjs/common'
|
|||||||
import { DocumentService } from './document.service'
|
import { DocumentService } from './document.service'
|
||||||
import { DocumentSchema } from './document.schema'
|
import { DocumentSchema } from './document.schema'
|
||||||
import { OpenaiModule } from 'src/OpenAI/openai.module'
|
import { OpenaiModule } from 'src/OpenAI/openai.module'
|
||||||
import { JSDOM } from 'jsdom'
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [OpenaiModule],
|
imports: [OpenaiModule],
|
||||||
providers: [JSDOM, DocumentService, DocumentSchema],
|
providers: [DocumentService, DocumentSchema],
|
||||||
exports: [DocumentService, DocumentSchema],
|
exports: [DocumentService, DocumentSchema],
|
||||||
})
|
})
|
||||||
export class DocumentModule {}
|
export class DocumentModule {}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import { Module } from '@nestjs/common'
|
import { Module, Global } from '@nestjs/common'
|
||||||
import { LiveKitService } from './livekit.service'
|
import { LiveKitService } from './livekit.service'
|
||||||
import { LiveKitParticipantService } from './livekit.participant.service'
|
@Global()
|
||||||
import { LiveKitRoomService } from './livekit.room.service'
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [LiveKitService, LiveKitParticipantService, LiveKitRoomService],
|
providers: [LiveKitService],
|
||||||
exports: [LiveKitService],
|
exports: [LiveKitService],
|
||||||
})
|
})
|
||||||
export class LiveKitModule {}
|
export class LiveKitModule {}
|
||||||
|
|||||||
@@ -1,20 +1,8 @@
|
|||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
// @ts-ignore
|
// @ts-expect-error
|
||||||
import { AccessToken } from 'livekit-server-sdk'
|
import { ParticipantPermission, RoomServiceClient } from 'livekit-server-sdk'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LiveKitParticipantService {
|
export class LiveKitParticipantService {
|
||||||
async createAccessToken(participantId: string) {
|
constructor(private readonly roomServiceClient: RoomServiceClient) {}
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
export class LiveKitRoomService {
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
constructor(private readonly roomServiceClient: RoomServiceClient) {}
|
||||||
private roomServiceClient: any
|
|
||||||
constructor() {
|
|
||||||
this.initializeRoomServiceClient()
|
|
||||||
}
|
|
||||||
|
|
||||||
private async initializeRoomServiceClient() {
|
async createServiceMeetingRoom(roomId: string) {
|
||||||
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) {
|
|
||||||
const room = await this.roomServiceClient.createRoom({
|
const room = await this.roomServiceClient.createRoom({
|
||||||
maxParticipants: 3,
|
name: roomId,
|
||||||
name: chattingRoomId,
|
maxParticipants: 2,
|
||||||
})
|
})
|
||||||
|
|
||||||
return room
|
return room
|
||||||
}
|
}
|
||||||
|
|
||||||
async createWorkshopMeetingRoom(workshopId: string, maxParticipants: number) {
|
async createWorkshopRoom(roomId: string, maxParticipants: number) {
|
||||||
const room = await this.roomServiceClient.createRoom({
|
const room = await this.roomServiceClient.createRoom({
|
||||||
maxParticipants: maxParticipants,
|
name: roomId,
|
||||||
name: workshopId,
|
maxParticipants,
|
||||||
})
|
})
|
||||||
return room
|
return room
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const roomServiceClient = forwardRef(() => LiveKitRoomService)
|
||||||
|
|||||||
@@ -1,15 +1,26 @@
|
|||||||
import { Injectable } from '@nestjs/common'
|
import { User } from '@prisma/client'
|
||||||
import { LiveKitRoomService } from './livekit.room.service'
|
import { Injectable, Logger } from '@nestjs/common'
|
||||||
import { LiveKitParticipantService } from './livekit.participant.service'
|
// @ts-expect-error
|
||||||
|
import { RoomServiceClient, AccessToken } from 'livekit-server-sdk'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LiveKitService {
|
export class LiveKitService {
|
||||||
constructor(
|
constructor() {}
|
||||||
private liveKitRoomService: LiveKitRoomService,
|
|
||||||
private liveKitParticipantService: LiveKitParticipantService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async createAccessToken(participantId: string) {
|
async createToken(me: User, roomName: string) {
|
||||||
return await this.liveKitParticipantService.createAccessToken(participantId)
|
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 { Injectable } from '@nestjs/common'
|
||||||
import { TrackInfo } from 'livekit-server-sdk'
|
|
||||||
|
|
||||||
export class LiveKitTrackService {
|
@Injectable()
|
||||||
}
|
export class LiveKitTrackService {}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { MailModule } from './Mail/mail.module'
|
|||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
import { RestfulModule } from './Restful/restful.module'
|
import { RestfulModule } from './Restful/restful.module'
|
||||||
import { CronModule } from './Cron/cron.module'
|
import { CronModule } from './Cron/cron.module'
|
||||||
// import { LiveKitModule } from './LiveKit/livekit.module'
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -17,7 +16,6 @@ import { CronModule } from './Cron/cron.module'
|
|||||||
GraphqlModule,
|
GraphqlModule,
|
||||||
RestfulModule,
|
RestfulModule,
|
||||||
CronModule,
|
CronModule,
|
||||||
// LiveKitModule,
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
Reference in New Issue
Block a user