2023-02-16 22:39:57 +00:00
|
|
|
import type { CalWindow } 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";
|
|
|
|
|
2022-05-18 16:25:30 +00:00
|
|
|
export const getCalApi = (): Promise<CalWindow["Cal"]> =>
|
|
|
|
new Promise(function tryReadingFromWindow(resolve) {
|
2022-06-09 05:05:18 +00:00
|
|
|
EmbedSnippet();
|
2022-05-18 16:25:30 +00:00
|
|
|
const api = (window as CalWindow).Cal;
|
|
|
|
if (!api) {
|
|
|
|
setTimeout(() => {
|
|
|
|
tryReadingFromWindow(resolve);
|
|
|
|
}, 50);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve(api);
|
|
|
|
});
|
|
|
|
|
2022-04-25 04:33:00 +00:00
|
|
|
export default Cal;
|