feat: enhance WorkshopMeetingRoomSchema with join info and LiveKit integration
- Added a new method `workshopMeetingRoomJoinInfo` to provide details for joining a workshop meeting room, including ID, token, and server URL. - Integrated LiveKitService to generate tokens and retrieve server URLs, improving the functionality of the workshop meeting room. - Updated the `init` method to include the new join info field, ensuring proper resolution and access control for users. - Enhanced error handling to ensure unauthorized access is properly managed during the join process.
This commit is contained in:
@@ -1,18 +1,14 @@
|
||||
import { Inject, Injectable } 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 } from '../Graphql/graphql.builder'
|
||||
import { PrismaService } from '../Prisma/prisma.service'
|
||||
|
||||
import { LiveKitService } from '../LiveKit/livekit.service'
|
||||
@Injectable()
|
||||
export class WorkshopMeetingRoomSchema extends PothosSchema {
|
||||
constructor(
|
||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly livekitService: LiveKitService,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
@@ -33,6 +29,22 @@ export class WorkshopMeetingRoomSchema extends PothosSchema {
|
||||
}),
|
||||
})
|
||||
}
|
||||
@PothosRef()
|
||||
workshopMeetingRoomJoinInfo() {
|
||||
return this.builder.simpleObject('WorkshopMeetingRoomJoinInfo', {
|
||||
fields: (t) => ({
|
||||
id: t.string({
|
||||
description: 'The ID of the workshop meeting room.',
|
||||
}),
|
||||
token: t.string({
|
||||
description: 'The token to join the workshop meeting room.',
|
||||
}),
|
||||
serverUrl: t.string({
|
||||
description: 'The URL of the server.',
|
||||
}),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@Pothos()
|
||||
init(): void {
|
||||
@@ -47,6 +59,31 @@ export class WorkshopMeetingRoomSchema extends PothosSchema {
|
||||
})
|
||||
},
|
||||
}),
|
||||
workshopMeetingRoomJoinInfo: t.field({
|
||||
type: this.workshopMeetingRoomJoinInfo(),
|
||||
args: {
|
||||
workshopId: t.arg({
|
||||
type: 'String',
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
resolve: async (_, args, ctx) => {
|
||||
if (ctx.isSubscription) throw new Error('Not allowed')
|
||||
if (!ctx.http?.me) throw new Error('Unauthorized')
|
||||
const meetingRoom = await this.prisma.workshopMeetingRoom.findUnique({
|
||||
where: {
|
||||
workshopId: args.workshopId,
|
||||
},
|
||||
})
|
||||
if (!meetingRoom) throw new Error('Meeting room not found')
|
||||
const serverUrl = this.livekitService.getServerUrl()
|
||||
return {
|
||||
id: meetingRoom.id,
|
||||
token: await this.livekitService.createToken(ctx.http?.me, meetingRoom.id),
|
||||
serverUrl,
|
||||
}
|
||||
},
|
||||
}),
|
||||
workshopMeetingRooms: t.prismaField({
|
||||
type: [this.workshopMeetingRoom()],
|
||||
args: this.builder.generator.findManyArgs('WorkshopMeetingRoom'),
|
||||
|
||||
Reference in New Issue
Block a user