Current Path : /storage/v11800/leadideascloud/public_html/wp-content/plugins/leadin/scripts/utils/ |
Linux v11800 5.3.0-1023-aws #25~18.04.1-Ubuntu SMP Fri Jun 5 15:19:18 UTC 2020 aarch64
|
Current File : /storage/v11800/leadideascloud/public_html/wp-content/plugins/leadin/scripts/utils/backgroundAppUtils.ts |
import {
deviceId,
hubspotBaseUrl,
locale,
portalId,
} from '../constants/leadinConfig';
import { initApp } from './appUtils';
type CallbackFn = (...args: any[]) => void;
export function initBackgroundApp(initFn: CallbackFn | CallbackFn[]) {
function main() {
if (Array.isArray(initFn)) {
initFn.forEach(callback => callback());
} else {
initFn();
}
}
initApp(main);
}
export const getOrCreateBackgroundApp = (refreshToken: string) => {
if ((window as any).LeadinBackgroundApp) {
return (window as any).LeadinBackgroundApp;
}
const { IntegratedAppEmbedder, IntegratedAppOptions }: any = window;
const options = new IntegratedAppOptions()
.setLocale(locale)
.setDeviceId(deviceId)
.setRefreshToken(refreshToken);
const embedder = new IntegratedAppEmbedder(
'integrated-plugin-proxy',
portalId,
hubspotBaseUrl,
() => {}
).setOptions(options);
embedder.attachTo(document.body, false);
embedder.postStartAppMessage(); // lets the app know all all data has been passed to it
(window as any).LeadinBackgroundApp = embedder;
return (window as any).LeadinBackgroundApp;
};