UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

102 lines (99 loc) 2.59 kB
/** * @package @bitrix24/b24jssdk * @version 1.0.1 * @copyright (c) 2026 Bitrix24 * @license MIT * @see https://github.com/bitrix24/b24jssdk * @see https://bitrix24.github.io/b24jssdk/ */ import { SdkError } from './core/sdk-error.mjs'; import { B24Frame } from './frame/b24.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); const delay = 50; let $b24Frame = null; let isInit = false; let connectError = null; let isMakeFirstCall = false; let listCallBack = []; let isStartWatch = false; function startWatch() { window.setTimeout(() => { if (!isInit || $b24Frame === null) { startWatch(); return; } processResult(); listCallBack = []; }, delay); } __name(startWatch, "startWatch"); function processResult() { if (null !== connectError) { for (const callBack of listCallBack) { callBack.reject(connectError); } } if (!isInit || $b24Frame === null) { return; } for (const callBack of listCallBack) { callBack.resolve($b24Frame); } } __name(processResult, "processResult"); async function initializeB24Frame(options) { if (isInit && null !== $b24Frame) { return Promise.resolve($b24Frame); } if (isMakeFirstCall) { if (!isStartWatch) { isStartWatch = true; startWatch(); } return new Promise((resolve, reject) => { listCallBack.push({ resolve, reject }); }); } isMakeFirstCall = true; return new Promise((resolve, reject) => { const queryParams = { DOMAIN: null, PROTOCOL: false, APP_SID: null, LANG: null }; if (window.name) { const [domain, protocol, appSid] = window.name.split("|"); queryParams.DOMAIN = domain; queryParams.PROTOCOL = Number.parseInt(protocol ?? "0") === 1; queryParams.APP_SID = appSid; queryParams.LANG = null; } if (!queryParams.DOMAIN || !queryParams.APP_SID) { connectError = new SdkError({ code: "JSSDK_CLIENT_SIDE_WARNING", description: "Well done! Now paste this URL into the Bitrix24 app settings", status: 500 }); reject(connectError); } $b24Frame = new B24Frame( queryParams, options ); $b24Frame.init().then(() => { isInit = true; resolve($b24Frame); }).catch((error) => { connectError = error; reject(connectError); }); }); } __name(initializeB24Frame, "initializeB24Frame"); export { initializeB24Frame }; //# sourceMappingURL=loader-b24frame.mjs.map