first commit
This commit is contained in:
40
calcom/packages/embeds/embed-react/src/index.ts
Normal file
40
calcom/packages/embeds/embed-react/src/index.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
"use client";
|
||||
|
||||
import type { GlobalCal, GlobalCalWithoutNs } from "@calcom/embed-core";
|
||||
import EmbedSnippet from "@calcom/embed-snippet";
|
||||
|
||||
import Cal from "./Cal";
|
||||
|
||||
export function getCalApi(options?: {
|
||||
embedJsUrl?: string;
|
||||
namespace?: string;
|
||||
}): Promise<GlobalCal | GlobalCalWithoutNs>;
|
||||
export function getCalApi(embedJsUrl: string): Promise<GlobalCal | GlobalCalWithoutNs>;
|
||||
|
||||
export function getCalApi(
|
||||
optionsOrEmbedJsUrl?:
|
||||
| {
|
||||
embedJsUrl?: string;
|
||||
namespace?: string;
|
||||
}
|
||||
| string
|
||||
): Promise<GlobalCal | GlobalCalWithoutNs> {
|
||||
const options =
|
||||
typeof optionsOrEmbedJsUrl === "string" ? { embedJsUrl: optionsOrEmbedJsUrl } : optionsOrEmbedJsUrl ?? {};
|
||||
|
||||
const { namespace = "", embedJsUrl } = options;
|
||||
return new Promise(function tryReadingFromWindow(resolve) {
|
||||
const globalCal = EmbedSnippet(embedJsUrl);
|
||||
globalCal("init", namespace);
|
||||
const api = namespace ? globalCal.ns[namespace as keyof typeof globalCal.ns] : globalCal;
|
||||
if (!api) {
|
||||
setTimeout(() => {
|
||||
tryReadingFromWindow(resolve);
|
||||
}, 50);
|
||||
return;
|
||||
}
|
||||
resolve(api);
|
||||
});
|
||||
}
|
||||
|
||||
export default Cal;
|
||||
Reference in New Issue
Block a user