@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) • 3.82 kB
JavaScript
;function __rest(e,o){var r={};for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&o.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var t=0,n=Object.getOwnPropertySymbols(e);t<n.length;t++)o.indexOf(n[t])<0&&Object.prototype.propertyIsEnumerable.call(e,n[t])&&(r[n[t]]=e[n[t]]);return r}Object.defineProperty(exports,"__esModule",{value:!0});const NO_RESPONSE_TIMEOUT_MS=1e3,NO_RESPONSE_ERROR={errorType:"client",errorCode:5,errorReason:"TIMEOUT_REACHED",errorMessage:`Request was failed. Response was not received in ${NO_RESPONSE_TIMEOUT_MS} ms timeout.`};function*createCounter(){let e=0;for(;;)yield e++}function createRequestResolver(){const r=createCounter(),n={};return{add(e,o){o=o||r.next().value;return n[o]=e,o},resolve(e,o,r){var t=n[e];t&&(r(o)?t.resolve(o):t.reject(o),delete n[e])}}}function promisifySend(n,e){const i=createRequestResolver();return e(e=>{var o;e&&e.data&&"object"==typeof e.data&&"requestId"in e.data&&(o=(e=e.data)["requestId"],e=__rest(e,["requestId"]),void 0!==o)&&i.resolve(o,e,e=>!("errorType"in e))}),function(r,t={}){return Promise.race([new Promise((e,o)=>{e=i.add({resolve:e,reject:o},t.requestId);n(r,Object.assign(Object.assign({},t),{requestId:e}))}),new Promise((e,o)=>{setTimeout(()=>o(NO_RESPONSE_ERROR),NO_RESPONSE_TIMEOUT_MS)})])}}var name="@open-condo/bridge",description="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 ",keywords=["condo","open-condo-software","client","bridge"],version="2.0.0",repository={type:"git",url:"git+https://github.com/open-condo-software/condo.git",directory:"packages/bridge"},author={name:"Matthew Savelev",email:"matthew@doma.ai",url:"https://github.com/SavelevMatthew"},license="MIT",files=["dist"],main="dist/index.js",module$1="dist/index.es.js",browser="dist/index.umd.js",types="dist/types/src/index.d.ts",scripts={build:"rm -rf dist && NODE_ENV=production rollup -c",watch:"rollup -c -w"},publishConfig={access:"public"},devDependencies={"@open-condo/tsconfig":"^1.0.4","@rollup/plugin-typescript":"^11.0.0",rollup:"^4.28.0","rollup-plugin-babel":"^4.3.3","rollup-plugin-bundle-size":"^1.0.3","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-json":"^4.0.0","rollup-plugin-node-resolve":"^5.2.0","rollup-plugin-uglify":"^6.0.4",tslib:"^2.4.1",typescript:"^5.8.3"},pkg={name:name,description:description,keywords:keywords,version:version,repository:repository,author:author,license:license,files:files,main:main,module:module$1,browser:browser,types:types,scripts:scripts,publishConfig:publishConfig,devDependencies:devDependencies};const IS_CLIENT_SIDE="undefined"!=typeof window,IS_BROWSER_CLIENT=IS_CLIENT_SIDE,WEB_SPECIFIC_METHODS=["CondoWebAppCloseModalWindow","CondoWebAppGetActiveProgressBars","CondoWebAppGetLaunchParams","CondoWebAppRedirect","CondoWebAppRequestAuth","CondoWebAppResizeWindow","CondoWebAppShowModalWindow","CondoWebAppShowNotification","CondoWebAppShowProgressBar","CondoWebAppUpdateModalWindow","CondoWebAppUpdateProgressBar"],ALL_METHODS=[...IS_BROWSER_CLIENT?WEB_SPECIFIC_METHODS:[]],webBridge=IS_BROWSER_CLIENT?parent:void 0;function createCondoBridge(){const r=[];function e(e){r.push(e)}return IS_BROWSER_CLIENT&&"addEventListener"in window&&window.addEventListener("message",function(e){const o=e.data;"object"==typeof o&&r.forEach(e=>e(o))}),{send:promisifySend(function(e,o){webBridge&&"function"==typeof webBridge.postMessage&&webBridge.postMessage({handler:e,params:o,type:"condo-bridge",version:pkg.version},"*")},e),supports:function(e){return ALL_METHODS.includes(e)},subscribe:e,unsubscribe:function(e){0<=(e=r.indexOf(e))&&r.splice(e,1)}}}const bridge=createCondoBridge();exports.default=bridge;
//# sourceMappingURL=index.js.map