From 7e674588b9ab03525a495637f2491c0313cae66a Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 11 Jul 2024 10:41:08 +0200 Subject: [PATCH] feat(backend): more meeting options (#1375) * Add body options to create Meeting Set default layout of BBB to VIDEO_FOCUS Set message to blank div, is there a way to use no space at all? May be CSS inside the div? Pass the invite link through the moderator only message * remove unused imports * fix typo --------- Co-authored-by: Hannes Heine --- backend/.env.dist | 3 +++ backend/src/api/BBB.ts | 16 +++++++++++++--- backend/src/api/BBB/types.ts | 13 +++++++++++++ backend/src/config/config.ts | 7 +++++++ .../src/graphql/resolvers/RoomResolver.spec.ts | 14 +++++++++++++- backend/src/graphql/resolvers/RoomResolver.ts | 16 ++++++++++++---- 6 files changed, 61 insertions(+), 8 deletions(-) diff --git a/backend/.env.dist b/backend/.env.dist index a2d1282487..421225f9c3 100644 --- a/backend/.env.dist +++ b/backend/.env.dist @@ -7,5 +7,8 @@ BREVO_NEWSLETTER_TEMPLATE_OPTIN="3" BREVO_NEWSLETTER_LIST="3" DATABASE_URL="mysql://root:@localhost:3306/dreammall.earth" +FRONTEND_URL="http://localhost:3000/" +INVITE_LINK_URL="${FRONTEND_URL}join-room/" + BBB_SHARED_SECRET="" BBB_URL="" diff --git a/backend/src/api/BBB.ts b/backend/src/api/BBB.ts index 373e2e569d..b7a76622d8 100644 --- a/backend/src/api/BBB.ts +++ b/backend/src/api/BBB.ts @@ -10,6 +10,8 @@ import { GetMeetingsResponse, CreateMeetingOptions, JoinMeetinLinkOptions, + CreateMeetingBodyOptions, + MeetingLayouts, } from './BBB/types' export { MeetingInfo, AttendeeInfo } from './BBB/types' @@ -20,6 +22,11 @@ const parser = new XMLParser({ isArray: (_, jpath) => alwaysArray.indexOf(jpath) !== -1, }) +const defaultCreateMeetingBodyOptions = { + welcome: '
', + meetingLayout: MeetingLayouts.VIDEO_FOCUS, +} + export const getMeetings = async (): Promise => { try { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment @@ -42,18 +49,21 @@ export const getMeetings = async (): Promise => { export const createMeeting = async ( options: CreateMeetingOptions, + bodyOptions: CreateMeetingBodyOptions = {}, ): Promise => { - const { name, meetingID /*, welcome */ } = options + const { name, meetingID } = options try { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const { data } = await axiosInstance.post( '/create', - {}, + { + ...defaultCreateMeetingBodyOptions, + ...bodyOptions, + }, { params: { name, meetingID, - // welcome, }, }, ) diff --git a/backend/src/api/BBB/types.ts b/backend/src/api/BBB/types.ts index 5c81d9c6ee..2ab96d0f6f 100644 --- a/backend/src/api/BBB/types.ts +++ b/backend/src/api/BBB/types.ts @@ -74,3 +74,16 @@ export interface JoinMeetinLinkOptions { createTime?: string userID?: string } + +export enum MeetingLayouts { + CUSTOM_LAYOUT = 'CUSTOM_LAYOUT', + SMART_LAYOUT = 'SMART_LAYOUT', + PRESENTATION_FOCUS = 'PRESENTATION_FOCUS', + VIDEO_FOCUS = 'VIDEO_FOCUS', +} + +export interface CreateMeetingBodyOptions { + welcome?: string + meetingLayout?: MeetingLayouts + moderatorOnlyMessage?: string +} diff --git a/backend/src/config/config.ts b/backend/src/config/config.ts index d8a1af7a7f..38cc27cace 100644 --- a/backend/src/config/config.ts +++ b/backend/src/config/config.ts @@ -35,9 +35,16 @@ const BBB = { BBB_PULL_MEETINGS: process.env.NODE_ENV !== 'test' && process.env.BBB_URL, } +const FRONTEND = { + FRONTEND_URL: process.env.FRONTEND_URL ?? 'http://localhost:3000/', + FRONTEND_INVITE_LINK_URL: + process.env.FRONTEND_INVITE_LINK_URL ?? 'http://localhost:3000/join-room/', +} + export const CONFIG = { ...BREVO, ...BBB, + ...FRONTEND, } // Config Checks diff --git a/backend/src/graphql/resolvers/RoomResolver.spec.ts b/backend/src/graphql/resolvers/RoomResolver.spec.ts index 6e8a3af7e7..c528a47520 100644 --- a/backend/src/graphql/resolvers/RoomResolver.spec.ts +++ b/backend/src/graphql/resolvers/RoomResolver.spec.ts @@ -3,6 +3,7 @@ import { ApolloServer } from '@apollo/server' import { gql } from 'graphql-tag' import { createMeeting, joinMeetingLink, getMeetings } from '#api/BBB' +import { CONFIG } from '#config/config' import { prisma } from '#src/prisma' import { createTestServer } from '#src/server/server' @@ -14,6 +15,8 @@ const getMeetingsMock = getMeetings as jest.MockedFunction let testServer: ApolloServer +CONFIG.FRONTEND_INVITE_LINK_URL = '/' + beforeAll(async () => { testServer = await createTestServer() }) @@ -340,7 +343,7 @@ describe('RoomResolver', () => { }) }) - it('creates meeting in database', async () => { + it('creates meeting in database and calls createMeeting', async () => { const result = await prisma.user.findFirst({ include: { meeting: true, @@ -363,6 +366,15 @@ describe('RoomResolver', () => { createDate: expect.any(Date), }, }) + expect(createMeetingMock).toBeCalledWith( + { + name: 'mockedUser', + meetingID: result?.meeting?.meetingID, + }, + { + moderatorOnlyMessage: `Use this link to invite more people:
/${result?.meeting?.id}`, + }, + ) }) }) diff --git a/backend/src/graphql/resolvers/RoomResolver.ts b/backend/src/graphql/resolvers/RoomResolver.ts index 153a8847a6..ec2df78f9a 100644 --- a/backend/src/graphql/resolvers/RoomResolver.ts +++ b/backend/src/graphql/resolvers/RoomResolver.ts @@ -14,6 +14,7 @@ import { import { v4 as uuidv4 } from 'uuid' import { createMeeting, joinMeetingLink, getMeetings, MeetingInfo } from '#api/BBB' +import { CONFIG } from '#config/config' import { Room, OpenRoom } from '#models/RoomModel' import logger from '#src/logger' import { prisma } from '#src/prisma' @@ -105,10 +106,17 @@ export class RoomResolver { throw new Error('Could not create Meeting in DB!') } - const meeting = await createMeeting({ - name: dbMeeting.name, - meetingID: dbMeeting.meetingID, - }) + const inviteLink = CONFIG.FRONTEND_INVITE_LINK_URL + dbMeeting.id + + const meeting = await createMeeting( + { + name: dbMeeting.name, + meetingID: dbMeeting.meetingID, + }, + { + moderatorOnlyMessage: `Use this link to invite more people:
${inviteLink}`, + }, + ) if (!meeting) throw new Error('Could not create meeting!')