2021-10-07 16:12:39 +00:00
|
|
|
import DailyIframe from "@daily-co/daily-js";
|
2023-01-25 08:51:09 +00:00
|
|
|
import { GetServerSidePropsContext } from "next";
|
2022-01-07 20:23:37 +00:00
|
|
|
import { getSession } from "next-auth/react";
|
2021-10-14 23:08:14 +00:00
|
|
|
import Head from "next/head";
|
2022-05-17 19:31:49 +00:00
|
|
|
import { useEffect } from "react";
|
2021-10-07 16:12:39 +00:00
|
|
|
|
2023-01-04 22:14:46 +00:00
|
|
|
import { APP_NAME, SEO_IMG_OGIMG_VIDEO, WEBSITE_URL } from "@calcom/lib/constants";
|
2022-05-18 21:05:49 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import prisma, { bookingMinimalSelect } from "@calcom/prisma";
|
|
|
|
import { inferSSRProps } from "@calcom/types/inferSSRProps";
|
2022-01-07 20:23:37 +00:00
|
|
|
|
2023-01-25 08:51:09 +00:00
|
|
|
import { ssrInit } from "@server/lib/ssr";
|
|
|
|
|
2022-01-07 20:23:37 +00:00
|
|
|
export type JoinCallPageProps = inferSSRProps<typeof getServerSideProps>;
|
2021-10-07 16:12:39 +00:00
|
|
|
|
2022-01-07 20:23:37 +00:00
|
|
|
export default function JoinCall(props: JoinCallPageProps) {
|
2022-02-15 12:46:27 +00:00
|
|
|
const { t } = useLocale();
|
2023-01-25 08:51:09 +00:00
|
|
|
const { meetingUrl, meetingPassword } = props;
|
2021-10-26 13:10:55 +00:00
|
|
|
|
2021-10-07 16:12:39 +00:00
|
|
|
useEffect(() => {
|
2022-08-11 00:53:05 +00:00
|
|
|
const callFrame = DailyIframe.createFrame({
|
|
|
|
theme: {
|
|
|
|
colors: {
|
|
|
|
accent: "#FFF",
|
|
|
|
accentText: "#111111",
|
|
|
|
background: "#111111",
|
|
|
|
backgroundAccent: "#111111",
|
|
|
|
baseText: "#FFF",
|
|
|
|
border: "#292929",
|
|
|
|
mainAreaBg: "#111111",
|
|
|
|
mainAreaBgAccent: "#111111",
|
|
|
|
mainAreaText: "#FFF",
|
|
|
|
supportiveText: "#FFF",
|
2021-10-26 13:10:55 +00:00
|
|
|
},
|
2022-08-11 00:53:05 +00:00
|
|
|
},
|
|
|
|
showLeaveButton: true,
|
|
|
|
iframeStyle: {
|
|
|
|
position: "fixed",
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
|
|
|
},
|
2023-01-25 08:51:09 +00:00
|
|
|
url: meetingUrl,
|
|
|
|
...(typeof meetingPassword === "string" && { token: meetingPassword }),
|
2022-08-11 00:53:05 +00:00
|
|
|
});
|
2023-01-25 08:51:09 +00:00
|
|
|
callFrame.join();
|
|
|
|
return () => {
|
|
|
|
callFrame.destroy();
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const title = `${APP_NAME} Video`;
|
2021-10-09 15:15:07 +00:00
|
|
|
return (
|
2021-10-14 23:08:14 +00:00
|
|
|
<>
|
|
|
|
<Head>
|
2023-01-25 08:51:09 +00:00
|
|
|
<title>{title}</title>
|
2023-01-04 22:14:46 +00:00
|
|
|
<meta name="title" content={APP_NAME + " Video"} />
|
2022-02-15 12:46:27 +00:00
|
|
|
<meta name="description" content={t("quick_video_meeting")} />
|
2022-07-01 17:19:52 +00:00
|
|
|
<meta property="og:image" content={SEO_IMG_OGIMG_VIDEO} />
|
2022-02-15 12:46:27 +00:00
|
|
|
<meta property="og:type" content="website" />
|
2022-07-01 17:19:52 +00:00
|
|
|
<meta property="og:url" content={`${WEBSITE_URL}/video`} />
|
2023-01-04 22:14:46 +00:00
|
|
|
<meta property="og:title" content={APP_NAME + " Video"} />
|
2022-02-15 12:46:27 +00:00
|
|
|
<meta property="og:description" content={t("quick_video_meeting")} />
|
2022-07-01 17:19:52 +00:00
|
|
|
<meta property="twitter:image" content={SEO_IMG_OGIMG_VIDEO} />
|
2022-02-15 12:46:27 +00:00
|
|
|
<meta property="twitter:card" content="summary_large_image" />
|
2022-07-01 17:19:52 +00:00
|
|
|
<meta property="twitter:url" content={`${WEBSITE_URL}/video`} />
|
2023-01-04 22:14:46 +00:00
|
|
|
<meta property="twitter:title" content={APP_NAME + " Video"} />
|
2022-02-15 12:46:27 +00:00
|
|
|
<meta property="twitter:description" content={t("quick_video_meeting")} />
|
2021-10-14 23:08:14 +00:00
|
|
|
</Head>
|
|
|
|
<div style={{ zIndex: 2, position: "relative" }}>
|
2022-10-26 13:31:19 +00:00
|
|
|
<img
|
|
|
|
className="h-5·w-auto fixed z-10 hidden sm:inline-block"
|
|
|
|
src={`${WEBSITE_URL}/cal-logo-word-dark.svg`}
|
|
|
|
alt="Cal.com Logo"
|
|
|
|
style={{
|
|
|
|
top: 46,
|
|
|
|
left: 24,
|
|
|
|
}}
|
|
|
|
/>
|
2021-10-14 23:08:14 +00:00
|
|
|
</div>
|
|
|
|
</>
|
2021-10-09 15:15:07 +00:00
|
|
|
);
|
2021-10-07 16:12:39 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 08:51:09 +00:00
|
|
|
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
|
|
|
const ssr = await ssrInit(context);
|
|
|
|
|
2021-10-26 13:10:55 +00:00
|
|
|
const booking = await prisma.booking.findUnique({
|
2021-10-07 16:12:39 +00:00
|
|
|
where: {
|
2022-01-07 20:23:37 +00:00
|
|
|
uid: context.query.uid as string,
|
2021-10-07 16:12:39 +00:00
|
|
|
},
|
|
|
|
select: {
|
2022-05-18 21:05:49 +00:00
|
|
|
...bookingMinimalSelect,
|
2021-10-26 13:10:55 +00:00
|
|
|
uid: true,
|
2021-10-07 16:12:39 +00:00
|
|
|
user: {
|
|
|
|
select: {
|
2022-01-07 20:23:37 +00:00
|
|
|
id: true,
|
2021-10-07 16:12:39 +00:00
|
|
|
credentials: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
references: {
|
|
|
|
select: {
|
|
|
|
uid: true,
|
|
|
|
type: true,
|
2022-08-11 00:53:05 +00:00
|
|
|
meetingUrl: true,
|
|
|
|
meetingPassword: true,
|
|
|
|
},
|
|
|
|
where: {
|
|
|
|
type: "daily_video",
|
2021-10-07 16:12:39 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-08-11 00:53:05 +00:00
|
|
|
if (!booking || booking.references.length === 0 || !booking.references[0].meetingUrl) {
|
|
|
|
return {
|
|
|
|
redirect: {
|
|
|
|
destination: "/video/no-meeting-found",
|
|
|
|
permanent: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//daily.co calls have a 60 minute exit buffer when a user enters a call when it's not available it will trigger the modals
|
|
|
|
const now = new Date();
|
|
|
|
const exitDate = new Date(now.getTime() - 60 * 60 * 1000);
|
|
|
|
|
|
|
|
//find out if the meeting is in the past
|
|
|
|
const isPast = booking?.endTime <= exitDate;
|
|
|
|
if (isPast) {
|
2021-10-26 13:10:55 +00:00
|
|
|
return {
|
2022-08-11 00:53:05 +00:00
|
|
|
redirect: {
|
|
|
|
destination: `/video/meeting-ended/${booking?.uid}`,
|
|
|
|
permanent: false,
|
|
|
|
},
|
2021-10-26 13:10:55 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const bookingObj = Object.assign({}, booking, {
|
|
|
|
startTime: booking.startTime.toString(),
|
|
|
|
endTime: booking.endTime.toString(),
|
|
|
|
});
|
2021-10-07 16:12:39 +00:00
|
|
|
const session = await getSession();
|
|
|
|
|
2022-08-11 00:53:05 +00:00
|
|
|
// set meetingPassword to null for guests
|
2022-11-23 18:35:08 +00:00
|
|
|
if (session?.user.id !== bookingObj.user?.id) {
|
2022-08-11 00:53:05 +00:00
|
|
|
bookingObj.references.forEach((bookRef) => {
|
|
|
|
bookRef.meetingPassword = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-07 16:12:39 +00:00
|
|
|
return {
|
|
|
|
props: {
|
2023-01-25 08:51:09 +00:00
|
|
|
meetingUrl: bookingObj.references[0].meetingUrl ?? "",
|
|
|
|
...(typeof bookingObj.references[0].meetingPassword === "string" && {
|
|
|
|
meetingPassword: bookingObj.references[0].meetingPassword,
|
|
|
|
}),
|
|
|
|
trpcState: ssr.dehydrate(),
|
2021-10-07 16:12:39 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|