UNPKG

@open-condo/bridge

Version:

A library that allows the client of your mini-application to communicate with the main user's client on different devices, using a common bridge API

3 lines (2 loc) 2.4 kB
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self)["@open-condo/bridge"]={})}(this,function(e){"use strict";const o={CondoWebAppRequestAuth:1e4};function n(e,n){const t=function(){const e=function*(){let e=0;for(;;)yield e++}(),o={};return{add(n,t){const r=t||e.next().value;return o[r]=n,r},resolve(e,n,t){const r=o[e];r&&(t(n)?r.resolve(n):r.reject(n),delete o[e])}}}();return n(e=>{if(e&&e.data&&"object"==typeof e.data&&"requestId"in e.data){const o=e.data,{requestId:n}=o,r=function(e,o){var n={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&o.indexOf(t)<0&&(n[t]=e[t]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(t=Object.getOwnPropertySymbols(e);r<t.length;r++)o.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(e,t[r])&&(n[t[r]]=e[t[r]])}return n}(o,["requestId"]);void 0!==n&&t.resolve(n,r,e=>!("errorType"in e))}}),function(n,r={},s){const d=s||o[n]||1e3;return Promise.race([new Promise((o,s)=>{const d=t.add({resolve:o,reject:s},r.requestId);e(n,Object.assign(Object.assign({},r),{requestId:d}))}),new Promise((e,o)=>{setTimeout(()=>o(function(e){return{errorType:"client",errorCode:5,errorReason:"TIMEOUT_REACHED",errorMessage:`Request was failed. Response was not received in ${e} ms timeout.`}}(d)),d)})])}}var t="2.3.0";const r="undefined"!=typeof window,s=[...r?["CondoWebAppCloseModalWindow","CondoWebAppGetActiveProgressBars","CondoWebAppGetFragment","CondoWebAppGetLaunchParams","CondoWebAppRedirect","CondoWebAppRequestAuth","CondoWebAppResizeWindow","CondoWebAppShowModalWindow","CondoWebAppShowNotification","CondoWebAppShowProgressBar","CondoWebAppUpdateModalWindow","CondoWebAppUpdateProgressBar"]:[]],d=r?parent:void 0;const i=function(){const e=[];function o(o){e.push(o)}return r&&"addEventListener"in window&&window.addEventListener("message",function(o){const n=o.data;"object"==typeof n&&e.forEach(e=>e(n))}),{send:n(function(e,o){d&&"function"==typeof d.postMessage&&d.postMessage({handler:e,params:o,type:"condo-bridge",version:t},"*")},o),supports:function(e){return s.includes(e)},subscribe:o,unsubscribe:function(o){const n=e.indexOf(o);n>=0&&e.splice(n,1)}}}();e.default=i,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=index.umd.js.map