2022-02-08 22:12:28 +00:00
|
|
|
import { v4 as uuidv4 } from "uuid";
|
|
|
|
|
2023-06-01 07:48:01 +00:00
|
|
|
import type { CalendarEvent } from "@calcom/types/Calendar";
|
2022-03-23 22:00:30 +00:00
|
|
|
import type { PartialReference } from "@calcom/types/EventManager";
|
|
|
|
import type { VideoApiAdapter, VideoCallData } from "@calcom/types/VideoApiAdapter";
|
2022-03-03 09:54:19 +00:00
|
|
|
|
2023-05-10 14:46:14 +00:00
|
|
|
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
|
|
|
|
import { metadata } from "../_metadata";
|
|
|
|
|
2022-02-08 22:12:28 +00:00
|
|
|
const JitsiVideoApiAdapter = (): VideoApiAdapter => {
|
|
|
|
return {
|
|
|
|
getAvailability: () => {
|
|
|
|
return Promise.resolve([]);
|
|
|
|
},
|
2023-06-01 07:48:01 +00:00
|
|
|
createMeeting: async (eventData: CalendarEvent): Promise<VideoCallData> => {
|
2023-05-10 14:46:14 +00:00
|
|
|
const appKeys = await getAppKeysFromSlug(metadata.slug);
|
|
|
|
|
2023-06-01 07:48:01 +00:00
|
|
|
const meetingPattern = (appKeys.jitsiPathPattern as string) || "{uuid}";
|
|
|
|
const hostUrl = (appKeys.jitsiHost as string) || "https://meet.jit.si/cal";
|
2023-05-10 14:46:14 +00:00
|
|
|
|
2023-06-01 07:48:01 +00:00
|
|
|
//Allows "/{Type}-with-{Attendees}" slug
|
|
|
|
const meetingID = meetingPattern
|
|
|
|
.replaceAll("{uuid}", uuidv4())
|
|
|
|
.replaceAll("{Title}", eventData.title)
|
|
|
|
.replaceAll("{Event Type Title}", eventData.type)
|
|
|
|
.replaceAll("{Scheduler}", eventData.attendees.map((a) => a.name).join("-"))
|
|
|
|
.replaceAll("{Organizer}", eventData.organizer.name)
|
|
|
|
.replaceAll("{Location}", eventData.location || "")
|
|
|
|
.replaceAll("{Team}", eventData.team?.name || "")
|
|
|
|
.replaceAll(" ", "-"); //Last Rule! - Replace all blanks (%20) with dashes;
|
2023-05-10 14:46:14 +00:00
|
|
|
|
2022-02-08 22:12:28 +00:00
|
|
|
return Promise.resolve({
|
2023-05-10 14:46:14 +00:00
|
|
|
type: metadata.type,
|
2022-02-08 22:12:28 +00:00
|
|
|
id: meetingID,
|
|
|
|
password: "",
|
2023-06-01 07:48:01 +00:00
|
|
|
url: hostUrl + "/" + encodeURIComponent(meetingID),
|
2022-02-08 22:12:28 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
deleteMeeting: async (): Promise<void> => {
|
|
|
|
Promise.resolve();
|
|
|
|
},
|
|
|
|
updateMeeting: (bookingRef: PartialReference): Promise<VideoCallData> => {
|
|
|
|
return Promise.resolve({
|
|
|
|
type: "jitsi_video",
|
|
|
|
id: bookingRef.meetingId as string,
|
|
|
|
password: bookingRef.meetingPassword as string,
|
|
|
|
url: bookingRef.meetingUrl as string,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default JitsiVideoApiAdapter;
|