cal.pub0.org/packages/embeds/embed-react/src/index.ts

20 lines
443 B
TypeScript
Raw Normal View History

2023-02-17 13:23:30 +00:00
import type { GlobalCal } from "@calcom/embed-core";
import EmbedSnippet from "@calcom/embed-snippet";
import Cal from "./Cal";
2023-02-17 13:23:30 +00:00
export const getCalApi = (): Promise<GlobalCal> =>
new Promise(function tryReadingFromWindow(resolve) {
EmbedSnippet();
2023-02-17 13:23:30 +00:00
const api = window.Cal;
if (!api) {
setTimeout(() => {
tryReadingFromWindow(resolve);
}, 50);
return;
}
resolve(api);
});
export default Cal;