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

22 lines
487 B
TypeScript
Raw Normal View History

"use client";
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";
export const getCalApi = (embedJsUrl?: string): Promise<GlobalCal> =>
new Promise(function tryReadingFromWindow(resolve) {
EmbedSnippet(embedJsUrl);
2023-02-17 13:23:30 +00:00
const api = window.Cal;
if (!api) {
setTimeout(() => {
tryReadingFromWindow(resolve);
}, 50);
return;
}
resolve(api);
});
export default Cal;