feat: integrate LiveKit services into Collaboration and Meeting Room modules
- Added LiveKitModule to CollaborationSession and MeetingRoom modules for enhanced real-time collaboration features. - Updated CollaborationSessionSchema to include LiveKit services for managing participant access and room permissions. - Implemented a new cron job in CronService to disable services without schedules for over 30 days, improving service management. - Enhanced GraphQL schema generation with improved filtering logic for better performance and readability. - Refactored LiveKit services to streamline access token creation and room management functionalities.
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { CollaborationSessionSchema } from './collaborationsession.schema'
|
||||
|
||||
import { LiveKitModule } from 'src/LiveKit/livekit.module'
|
||||
import { LiveKitService } from 'src/LiveKit/livekit.service'
|
||||
import { LiveKitParticipantService } from 'src/LiveKit/livekit.participant.service'
|
||||
import { LiveKitRoomService } from 'src/LiveKit/livekit.room.service'
|
||||
@Module({
|
||||
providers: [CollaborationSessionSchema],
|
||||
imports: [LiveKitModule],
|
||||
providers: [CollaborationSessionSchema, LiveKitService, LiveKitParticipantService, LiveKitRoomService],
|
||||
exports: [CollaborationSessionSchema],
|
||||
})
|
||||
export class CollaborationSessionModule {}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common'
|
||||
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
||||
import { Builder } from '../Graphql/graphql.builder'
|
||||
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 { DateTimeUtils } from 'src/common/utils/datetime.utils'
|
||||
import { LiveKitService } from 'src/LiveKit/livekit.service'
|
||||
import { LiveKitParticipantService } from 'src/LiveKit/livekit.participant.service'
|
||||
@Injectable()
|
||||
export class CollaborationSessionSchema extends PothosSchema {
|
||||
constructor(
|
||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||
private readonly prisma: PrismaService,
|
||||
// private readonly liveKitRoomService: LiveKitRoomService,
|
||||
private readonly liveKitService: LiveKitService,
|
||||
private readonly liveKitParticipantService: LiveKitParticipantService,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
@@ -99,6 +102,7 @@ export class CollaborationSessionSchema extends PothosSchema {
|
||||
// },
|
||||
// })
|
||||
// }
|
||||
|
||||
// check if user is participant
|
||||
if (
|
||||
!collaborationSession.collaboratorsIds.includes(ctx.http.me.id) ||
|
||||
@@ -182,6 +186,29 @@ export class CollaborationSessionSchema extends PothosSchema {
|
||||
})
|
||||
},
|
||||
}),
|
||||
liveKitToken: t.field({
|
||||
type: 'String',
|
||||
resolve: async (_, _args, ctx: SchemaContext) => {
|
||||
if (ctx.isSubscription) throw new Error('Not allowed')
|
||||
if (!ctx.http?.me?.id) throw new Error('User not found')
|
||||
// check if participantId is in meetingRoomCollaborators
|
||||
const meetingRoomCollaborator = await this.prisma.meetingRoomCollaborator.findFirst({
|
||||
where: {
|
||||
userId: ctx.http.me.id,
|
||||
},
|
||||
})
|
||||
if (!meetingRoomCollaborator) throw new Error('Meeting room collaborator not found')
|
||||
const meetingRoom = await this.prisma.meetingRoom.findUnique({
|
||||
where: {
|
||||
id: meetingRoomCollaborator.meetingRoomId,
|
||||
},
|
||||
})
|
||||
if (!meetingRoom) throw new Error('Meeting room not found')
|
||||
const token = await this.liveKitService.createAccessToken(ctx.http.me.id)
|
||||
await this.liveKitParticipantService.grantRoomJoinPermission(token, meetingRoom.collaborationSessionId)
|
||||
return await this.liveKitParticipantService.toJWT(token)
|
||||
},
|
||||
}),
|
||||
}))
|
||||
|
||||
this.builder.mutationFields((t) => ({
|
||||
|
||||
Reference in New Issue
Block a user