fix: backward compatibility for old cal rooms (#15609)
* fix: record icon for old rooms * chore: change function name
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import MarkdownIt from "markdown-it";
|
||||
import type { GetServerSidePropsContext } from "next";
|
||||
|
||||
import { generateGuestMeetingTokenFromOwnerMeetingToken } from "@calcom/app-store/dailyvideo/lib/VideoApiAdapter";
|
||||
import {
|
||||
generateGuestMeetingTokenFromOwnerMeetingToken,
|
||||
setEnableRecordingUIForOrganizer,
|
||||
} from "@calcom/app-store/dailyvideo/lib/VideoApiAdapter";
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import { getCalVideoReference } from "@calcom/features/get-cal-video-reference";
|
||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||
@@ -40,6 +43,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
},
|
||||
references: {
|
||||
select: {
|
||||
id: true,
|
||||
uid: true,
|
||||
type: true,
|
||||
meetingUrl: true,
|
||||
@@ -104,17 +108,30 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
|
||||
const session = await getServerSession({ req });
|
||||
|
||||
const oldVideoReference = getCalVideoReference(bookingObj.references);
|
||||
|
||||
// set meetingPassword for guests
|
||||
if (session?.user.id !== bookingObj.user?.id) {
|
||||
const videoReference = getCalVideoReference(bookingObj.references);
|
||||
const guestMeetingPassword = await generateGuestMeetingTokenFromOwnerMeetingToken(
|
||||
videoReference.meetingPassword
|
||||
oldVideoReference.meetingPassword
|
||||
);
|
||||
|
||||
bookingObj.references.forEach((bookRef) => {
|
||||
bookRef.meetingPassword = guestMeetingPassword;
|
||||
});
|
||||
}
|
||||
// Only for backward compatibility for organizer
|
||||
else {
|
||||
const meetingPassword = await setEnableRecordingUIForOrganizer(
|
||||
oldVideoReference.id,
|
||||
oldVideoReference.meetingPassword
|
||||
);
|
||||
if (!!meetingPassword) {
|
||||
bookingObj.references.forEach((bookRef) => {
|
||||
bookRef.meetingPassword = meetingPassword;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const videoReference = getCalVideoReference(bookingObj.references);
|
||||
|
||||
|
||||
@@ -116,6 +116,38 @@ export const generateGuestMeetingTokenFromOwnerMeetingToken = async (meetingToke
|
||||
return guestMeetingToken.token;
|
||||
};
|
||||
|
||||
// Only for backward compatibility
|
||||
export const setEnableRecordingUIForOrganizer = async (
|
||||
bookingReferenceId: number,
|
||||
meetingToken: string | null
|
||||
) => {
|
||||
if (!meetingToken) return null;
|
||||
|
||||
const token = await fetcher(`/meeting-tokens/${meetingToken}`).then(ZGetMeetingTokenResponseSchema.parse);
|
||||
if (token.enable_recording_ui === false) return null;
|
||||
|
||||
const organizerMeetingToken = await postToDailyAPI("/meeting-tokens", {
|
||||
properties: {
|
||||
room_name: token.room_name,
|
||||
exp: token.exp,
|
||||
enable_recording_ui: false,
|
||||
is_owner: true,
|
||||
},
|
||||
}).then(meetingTokenSchema.parse);
|
||||
|
||||
// Update the meetingPassword in the database
|
||||
await prisma.bookingReference.update({
|
||||
where: {
|
||||
id: bookingReferenceId,
|
||||
},
|
||||
data: {
|
||||
meetingPassword: organizerMeetingToken.token,
|
||||
},
|
||||
});
|
||||
|
||||
return organizerMeetingToken.token;
|
||||
};
|
||||
|
||||
const DailyVideoApiAdapter = (): VideoApiAdapter => {
|
||||
async function createOrUpdateMeeting(endpoint: string, event: CalendarEvent): Promise<VideoCallData> {
|
||||
if (!event.uid) {
|
||||
|
||||
@@ -62,5 +62,6 @@ export const ZGetMeetingTokenResponseSchema = z
|
||||
.object({
|
||||
room_name: z.string(),
|
||||
exp: z.number(),
|
||||
enable_recording_ui: z.boolean().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export type Reference = {
|
||||
id: number;
|
||||
uid: string;
|
||||
type: string;
|
||||
meetingUrl: string | null;
|
||||
|
||||
Reference in New Issue
Block a user