2023-03-28 06:00:02 +00:00
|
|
|
"use client";
|
|
|
|
|
2023-02-17 13:23:30 +00:00
|
|
|
import type { GlobalCal } from "@calcom/embed-core";
|
2022-06-09 05:05:18 +00:00
|
|
|
import EmbedSnippet from "@calcom/embed-snippet";
|
2022-05-18 16:25:30 +00:00
|
|
|
|
2022-04-25 04:33:00 +00:00
|
|
|
import Cal from "./Cal";
|
|
|
|
|
2023-03-28 18:17:40 +00:00
|
|
|
export const getCalApi = (embedJsUrl?: string): Promise<GlobalCal> =>
|
2022-05-18 16:25:30 +00:00
|
|
|
new Promise(function tryReadingFromWindow(resolve) {
|
2023-03-28 18:17:40 +00:00
|
|
|
EmbedSnippet(embedJsUrl);
|
2023-02-17 13:23:30 +00:00
|
|
|
const api = window.Cal;
|
2022-05-18 16:25:30 +00:00
|
|
|
if (!api) {
|
|
|
|
setTimeout(() => {
|
|
|
|
tryReadingFromWindow(resolve);
|
|
|
|
}, 50);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve(api);
|
|
|
|
});
|
|
|
|
|
2022-04-25 04:33:00 +00:00
|
|
|
export default Cal;
|