feat: enhance collaboration session and LiveKit integration
- Added LiveKitRoomService to manage meeting room creation and recording functionalities. - Updated CollaborationSessionSchema to create a LiveKit room upon new collaboration session creation. - Introduced meetingRoomJoinInfo field in MeetingRoomSchema to provide join tokens and server URLs for meeting rooms. - Improved LiveKitService to include user metadata in token generation and added a method to retrieve the server URL. - Enhanced error handling and authorization checks across schemas to ensure proper access control for collaboration sessions and meeting rooms.
This commit is contained in:
@@ -2,11 +2,13 @@ import { Inject, Injectable } from '@nestjs/common'
|
||||
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
||||
import { Builder, SchemaContext } from 'src/Graphql/graphql.builder'
|
||||
import { PrismaService } from 'src/Prisma/prisma.service'
|
||||
import { LiveKitService } from 'src/LiveKit/livekit.service'
|
||||
@Injectable()
|
||||
export class MeetingRoomSchema extends PothosSchema {
|
||||
constructor(
|
||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly livekitService: LiveKitService,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
@@ -24,6 +26,23 @@ export class MeetingRoomSchema extends PothosSchema {
|
||||
})
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
meetingRoomJoinInfo() {
|
||||
return this.builder.simpleObject('MeetingRoomJoinInfo', {
|
||||
fields: (t) => ({
|
||||
id: t.string({
|
||||
description: 'The ID of the meeting room.',
|
||||
}),
|
||||
token: t.string({
|
||||
description: 'The token to join the meeting room.',
|
||||
}),
|
||||
serverUrl: t.string({
|
||||
description: 'The URL of the server.',
|
||||
}),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
meetingRoomCollaborator() {
|
||||
return this.builder.prismaObject('MeetingRoomCollaborator', {
|
||||
@@ -69,13 +88,50 @@ export class MeetingRoomSchema extends PothosSchema {
|
||||
})
|
||||
},
|
||||
}),
|
||||
// get meeting room info by room id and check if user is collaborator of collaboration session then create new token and return it,
|
||||
// if not collaborator then throw error
|
||||
meetingRoomJoinInfo: t.field({
|
||||
type: this.meetingRoomJoinInfo(),
|
||||
args: {
|
||||
collaborationSessionId: t.arg.string({
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
resolve: async (_, args, ctx: SchemaContext) => {
|
||||
if (ctx.isSubscription) throw new Error('Not allowed')
|
||||
if (!ctx.http.me) throw new Error('Unauthorized')
|
||||
const meetingRoom = await this.prisma.meetingRoom.findUnique({
|
||||
where: { collaborationSessionId: args.collaborationSessionId },
|
||||
})
|
||||
if (!meetingRoom) throw new Error('Meeting room not found')
|
||||
// check if user is collaborator of collaboration session
|
||||
const collaborationSession = await this.prisma.collaborationSession.findUnique({
|
||||
where: { id: meetingRoom.collaborationSessionId },
|
||||
})
|
||||
if (!collaborationSession) throw new Error('Collaboration session not found')
|
||||
if (!collaborationSession.collaboratorsIds.includes(ctx.http.me.id))
|
||||
throw new Error('User is not collaborator')
|
||||
// create new token
|
||||
const token = await this.livekitService.createToken(ctx.http.me, meetingRoom.id)
|
||||
return {
|
||||
id: meetingRoom.id,
|
||||
token,
|
||||
serverUrl: this.livekitService.getServerUrl(),
|
||||
}
|
||||
},
|
||||
}),
|
||||
}))
|
||||
this.builder.mutationFields((t) => ({
|
||||
createMeetingRoom: t.prismaField({
|
||||
type: this.meetingRoom(),
|
||||
args: {
|
||||
input: t.arg({
|
||||
type: this.builder.generator.getCreateInput('MeetingRoom', ['id', 'createdAt', 'updatedAt']),
|
||||
type: this.builder.generator.getCreateInput('MeetingRoom', [
|
||||
'id',
|
||||
'createdAt',
|
||||
'updatedAt',
|
||||
'collaborators',
|
||||
]),
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user