UNPKG

atriusmaps-node-sdk

Version:

This project provides an API to Atrius Personal Wayfinder maps within a Node environment. See the README.md for more information

2 lines (1 loc) 1.78 kB
import e from"node:http";import t from"node:https";import{HttpsProxyAgent as n}from"https-proxy-agent";import o from"node-fetch";import r from"../deploy/prepareSDKConfig.js";import s from"../package.json.js";import{create as c}from"../src/controller.js";import i from"../src/utils/observable.js";const a=s.version;let g=!1;const m=e=>e.toString().length<2?"0"+e:e,p=()=>`AtriusMaps Node SDK (${(()=>{const e=new Date;return`${e.getHours()}:${m(e.getMinutes())}:${m(e.getSeconds())}.${e.getMilliseconds()}`})()}): `,l=function(){if(g){let e=p()+Array.from(arguments).map((e=>"object"==typeof e?JSON.stringify(e):e)).join(" ");const t=e.split("\n");t.length>1?e=t[0]+`… (+ ${t.length-1} lines)`:e.length>256&&(e=e.substring(0,255)+`… (length: ${e.length} chars)`),console.log(e)}};async function f(s){return new Promise(((a,g)=>{s.headless=!0,function(r){const s=new e.Agent({keepAlive:!0}),c=new t.Agent({keepAlive:!0}),i=r.proxy?new n(`http://${r.proxy.host}:${r.proxy.port}`):null,a=r.agent||i||(e=>"http:"===e.protocol?s:c);global.fetch=async(e,t)=>o(e,{...t,agent:a})}(s);const m=r(s);c(m).then((e=>{const t=(t,n)=>("string"==typeof t&&(t={...n,command:t}),l("Sending command object: ",t),e.bus.get("clientAPI/execute",t).then((e=>(l("Received Message: ",e),e))).catch((e=>{throw l("Error: ",e.message),e})));i(t),e.eventListener.observe((function(){t.fire.apply(t,arguments)})),t.on("ready",((e,n)=>{const{commands:o}=n.commandJSON;!function(e,t){t.forEach((t=>{e[t.command]=function(){const n={command:t.command};for(let e=0;e<arguments.length;e++)n[t.args[e].name]=arguments[e];return e(n)}}))}(t,o),a(t),l("map ready")}))}))}))}const h={getVersion:()=>a,newMap:e=>f(e),setLogging:e=>{g=e,e&&l(`Atrius Maps JS SDK Client v${a} Logging enabled.`)}};export{h as default};