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