text: !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).unet={})}(this,(function(e){"use strict";const t="undefined"!=typeof window&&void 0!==window.document,s="object"==typeof self&&self.constructor&&"DedicatedWorkerGlobalScope"===self.constructor.name,n="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node,r="open",i="opening";var o;class a{constructor(e={}){this.url=new URL("tcp://localhost");let t=e.hostname||"localhost",s=e.port||-1;this.url.hostname=e.hostname,this.url.port=e.port,this._buf="",this.pendingOnOpen=[],this.connListeners=[],this._sockInit(t,s)}_sendConnEvent(e){this.connListeners.forEach((t=>{t&&"[object Function]"==={}.toString.call(t)&&t(e)}))}_sockInit(e,t){if(o)this._sockSetup(e,t);else try{import("net").then((s=>{o=s.createConnection,this._sockSetup(e,t)}))}catch(e){this.debug&&console.log("Unable to import net module")}}_sockSetup(e,t){if(o)try{this.sock=o({host:e,port:t}),this.sock.setEncoding("utf8"),this.sock.on("connect",this._onSockOpen.bind(this)),this.sock.on("error",this._sockReconnect.bind(this)),this.sock.on("close",(()=>{this._sendConnEvent(!1)})),this.sock.send=e=>{this.sock.write(e)}}catch(e){return void(this.debug&&console.log("Connection failed to ",this.sock.host+":"+this.sock.port))}}_sockReconnect(){!this._firstConn&&this.keepAlive&&this.sock.readyState!=i&&this.sock.readyState!=r&&(this._firstReConn&&this._sendConnEvent(!1),this._firstReConn=!1,this.debug&&console.log("Reconnecting to ",this.sock.remoteAddress+":"+this.sock.remotePort),setTimeout((()=>{this.pendingOnOpen=[],this._sockSetup(this.sock.url)}),this._reconnectTime))}_onSockOpen(){this._sendConnEvent(!0),this.sock.on("close",this._sockReconnect.bind(this)),this.sock.on("data",this._processSockData.bind(this)),this.pendingOnOpen.forEach((e=>e())),this.pendingOnOpen.length=0,this._buf=""}_processSockData(e){this._buf+=e;var t=this._buf.split("\n");t.forEach(((e,s)=>{s<t.length-1?e&&this._onSockRx&&this._onSockRx.call(this,e):this._buf=e}))}toString(){let e="";return e+=(this.sock,this.sock.remoteAddress.toString()+":"+this.sock.remotePort.toString()),e}write(e){return this.sock&&this.sock.readyState!=i?this.sock.readyState==r&&(this.sock.send(e+"\n"),!0):(this.pendingOnOpen.push((()=>{this.sock.send(e+"\n")})),!0)}setReadCallback(e){e&&"[object Function]"==={}.toString.call(e)&&(this._onSockRx=e)}addConnectionListener(e){this.connListeners.push(e)}removeConnectionListener(e){let t=this.connListeners.indexOf(e);return t>=0&&(this.connListeners.splice(t,1),!0)}close(){this.sock&&(this.sock.readyState==i?this.pendingOnOpen.push((()=>{this.sock.send('{"alive": false}\n'),this.sock.onclose=null,this.sock.destroy()})):this.sock.readyState==r&&(this.sock.send('{"alive": false}\n'),this.sock.onclose=null,this.sock.destroy()))}}class l{constructor(e={}){this.url=new URL("ws://localhost"),this.url.hostname=e.hostname,this.url.port=e.port,this.url.pathname=e.pathname,this._reconnectTime=e.reconnectTime||5e3,this._keepAlive=e.keepAlive,this.debug=e.debug||!1,this._firstConn=!0,this._firstReConn=!0,this.pendingOnOpen=[],this.connListeners=[],this._websockSetup(this.url)}_sendConnEvent(e){this.connListeners.forEach((t=>{t&&"[object Function]"==={}.toString.call(t)&&t(e)}))}_websockSetup(e){try{this.sock=new WebSocket(e),this.sock.onerror=this._websockReconnect.bind(this),this.sock.onopen=this._onWebsockOpen.bind(this),this.sock.onclose=()=>{this._sendConnEvent(!1)}}catch(t){return void(this.debug&&console.log("Connection failed to ",e))}}_websockReconnect(){!this._firstConn&&this._keepAlive&&this.sock.readyState!=this.sock.CONNECTING&&this.sock.readyState!=this.sock.OPEN&&(this._firstReConn&&this._sendConnEvent(!1),this._firstReConn=!1,this.debug&&console.log("Reconnecting to ",this.sock.url),setTimeout((()=>{this.pendingOnOpen=[],this._websockSetup(this.sock.url)}),this._reconnectTime))}_onWebsockOpen(){this.debug&&console.log("Connected to ",this.sock.url),this._sendConnEvent(!0),this.sock.onclose=this._websockReconnect.bind(this),this.sock.onmessage=e=>{this._onWebsockRx&&this._onWebsockRx.call(this,e.data)},this._firstConn=!1,this._firstReConn=!0,this.pendingOnOpen.forEach((e=>e())),this.pendingOnOpen.length=0}toString(){let e="";return e+=(this.sock,this.sock.url.toString()),e}write(e){return this.sock&&this.sock.readyState!=this.sock.CONNECTING?this.sock.readyState==this.sock.OPEN&&(this.sock.send(e+"\n"),!0):(this.pendingOnOpen.push((()=>{this.sock.send(e+"\n")})),!0)}setReadCallback(e){e&&"[object Function]"==={}.toString.call(e)&&(this._onWebsockRx=e)}addConnectionListener(e){this.connListeners.push(e)}removeConnectionListener(e){let t=this.connListeners.indexOf(e);return t>=0&&(this.connListeners.splice(t,1),!0)}close(){this.sock&&(this.sock.readyState==this.sock.CONNECTING?this.pendingOnOpen.push((()=>{this.sock.send('{"alive": false}\n'),this.sock.onclose=null,this.sock.close()})):this.sock.readyState==this.sock.OPEN&&(this.sock.send('{"alive": false}\n'),this.sock.onclose=null,this.sock.close()))}}const c={REQUEST:"REQUEST",AGREE:"AGREE",REFUSE:"REFUSE",FAILURE:"FAILURE",INFORM:"INFORM",CONFIRM:"CONFIRM",DISCONFIRM:"DISCONFIRM",QUERY_IF:"QUERY_IF",NOT_UNDERSTOOD:"NOT_UNDERSTOOD",CFP:"CFP",PROPOSE:"PROPOSE",CANCEL:"CANCEL"};class h{constructor(e,t,s){this.name=e,this.topic=t,this.owner=s}getName(){return this.name}isTopic(){return this.topic}send(e){e.recipient=this.toJSON(),this.owner.send(e)}async request(e,t=1e3){return e.recipient=this.toJSON(),this.owner.request(e,t)}toString(){return this.toJSON()+(this.owner&&this.owner.connector?` on ${this.owner.connector.url}`:"")}toJSON(){return(this.topic?"#":"")+this.name}async set(e,t,s=-1,n=5e3){if(!e)return null;let r=new v;r.recipient=this.name,Array.isArray(e)?r.requests=e.map(((e,s)=>({param:e,value:t[s]}))):(r.param=e,r.value=t),r.index=Number.isInteger(s)?s:-1;const i=await this.owner.request(r,n);var o=Array.isArray(e)?new Array(e.length).fill(null):null;if(!i||i.perf!=c.INFORM||!i.param)return o;if(Array.isArray(e)){i.values||(i.values={}),i.param&&(i.values[i.param]=i.value);const t=Object.keys(i.values);return e.map((e=>{let s=t.find((t=>t.endsWith(e)));return s?i.values[s]:null}))}return i.value}async get(e,t=-1,s=5e3){let n=new v;n.recipient=this.name,e&&(Array.isArray(e)?n.requests=e.map((e=>({param:e}))):n.param=e),n.index=Number.isInteger(t)?t:-1;const r=await this.owner.request(n,s);var i=Array.isArray(e)?new Array(e.length).fill(null):null;if(!r||r.perf!=c.INFORM||e&&!r.param)return i;if(e){if(Array.isArray(e)){r.values||(r.values={}),r.param&&(r.values[r.param]=r.value);const t=Object.keys(r.values);return e.map((e=>{let s=t.find((t=>t.endsWith(e)));return s?r.values[s]:null}))}return r.value}return r.values||(r.values={}),r.param&&(r.values[r.param]=r.value),r.values}}class u{constructor(e={msgID:null,sender:null},t=""){this.__clazz__="org.arl.fjage.Message",this.msgID=f(8),this.sender=null,this.recipient=e.sender,this.perf=t,this.inReplyTo=e.msgID||null}toString(){let e="",t="";if(!this.__clazz__)return"";let s=this.__clazz__;s=s.replace(/^.*\./,"");let n=this.perf;for(var r in this)r.startsWith("__")||"sender"!=r&&"recipient"!=r&&"msgID"!=r&&"perf"!=r&&"inReplyTo"!=r&&("object"!=typeof this[r]?e+=" "+r+":"+this[r]:t=" ...");return e+=t,s+":"+n+"["+e.replace(/^ /,"")+"]"}_serialize(){return'{ "clazz": "'+(this.__clazz__||"org.arl.fjage.Message")+'", "data": '+JSON.stringify(this,((e,t)=>{if(!e.startsWith("__"))return t}))+" }"}_inflate(e){for(var t in e)this[t]=e[t]}static _deserialize(e){if("string"==typeof e||e instanceof String)try{e=JSON.parse(e)}catch(e){return null}let t=e.clazz,s=t.replace(/^.*\./,""),n=p[s]?new p[s]:new u;return n.__clazz__=t,n._inflate(e.data),n}}class g{constructor(e={},s,n="/ws/",r=1e3){("string"==typeof e||e instanceof String)&&(e={hostname:e,port:s||_.location.port,pathname:n,timeout:r},console.warn("Deprecated use of Gateway constructor")),e=Object.assign({},m,e);var i=S;i.hostname=e.hostname,i.port=e.port,i.pathname=e.pathname;let o=this._getGWCache(i);if(o)return o;this._timeout=e.timeout,this._keepAlive=e.keepAlive,this._queueSize=e.queueSize,this.pending={},this.subscriptions={},this.listener={},this.eventListeners={},this.queue=[],this.debug=!1,this.aid=new h(t?"WebGW-":"NodeGW-"+f(4)),this.connector=this._createConnector(i),this._addGWCache(this)}_sendEvent(e,t){Array.isArray(this.eventListeners[e])&&this.eventListeners[e].forEach((e=>{e&&"[object Function]"==={}.toString.call(e)&&e(t)}))}_onMsgRx(e){var t;this.debug&&console.log("< "+e),this._sendEvent("rx",e);try{t=JSON.parse(e,R)}catch(e){return}if(this._sendEvent("rxp",t),"id"in t&&t.id in this.pending)this.pending[t.id](t),delete this.pending[t.id];else if("send"==t.action){let e=u._deserialize(t.message);if(!e)return;if(this._sendEvent("rxmsg",e),e.recipient==this.aid.toJSON()||this.subscriptions[e.recipient]){var s=!1;if(Array.isArray(this.eventListeners.message))for(var n=0;n<this.eventListeners.message.length;n++)if(this.eventListeners.message[n](e)){s=!0;break}for(var r in this.listener)if(this.listener[r](e)){s=!0;break}s||(this.queue.length>=this._queueSize&&this.queue.shift(),this.queue.push(e))}}else{let e={id:t.id,inResponseTo:t.action};switch(t.action){case"agents":e.agentIDs=[this.aid.getName()];break;case"containsAgent":e.answer=t.agentID==this.aid.getName();break;case"services":e.services=[];break;case"agentForService":e.agentID="";break;case"agentsForService":e.agentIDs=[];break;default:e=void 0}e&&this._msgTx(e)}}_msgTx(e){return"string"==typeof e||e instanceof String||(e=JSON.stringify(e)),this.debug&&console.log("> "+e),this._sendEvent("tx",e),this.connector.write(e)}_msgTxRx(e){return e.id=f(8),new Promise((t=>{let s=setTimeout((()=>{delete this.pending[e.id],this.debug&&console.log("Receive Timeout : "+e),t()}),8*this._timeout);this.pending[e.id]=e=>{clearTimeout(s),t(e)},this._msgTx.call(this,e)||(clearTimeout(s),delete this.pending[e.id],this.debug&&console.log("Transmit Timeout : "+e),t())}))}_createConnector(e){let t;if(e.protocol.startsWith("ws"))t=new l({hostname:e.hostname,port:e.port,pathname:e.pathname,keepAlive:this._keepAlive});else{if(!e.protocol.startsWith("tcp"))return null;t=new a({hostname:e.hostname,port:e.port,keepAlive:this._keepAlive})}return t.setReadCallback(this._onMsgRx.bind(this)),t.addConnectionListener((e=>{1==e&&(this.flush(),this.connector.write('{"alive": true}'),this._update_watch())})),t}_matchMessage(e,t){return"string"==typeof e||e instanceof String?"inReplyTo"in t&&t.inReplyTo==e:Object.prototype.hasOwnProperty.call(e,"msgID")?"inReplyTo"in t&&t.inReplyTo==e.msgID:"Message"==e.__proto__.name?e.__clazz__==t.__clazz__:"function"==typeof e?e(t):t instanceof e}_getMessageFromQueue(e){if(!this.queue.length)return;if(!e)return this.queue.shift();let t=this.queue.find((t=>this._matchMessage(e,t)));return t&&this.queue.splice(this.queue.indexOf(t),1),t}_getGWCache(e){if(!_.fjage||!_.fjage.gateways)return null;var t=_.fjage.gateways.filter((t=>t.connector.url.toString()==e.toString()));return t.length?t[0]:null}_addGWCache(e){_.fjage&&_.fjage.gateways&&_.fjage.gateways.push(e)}_removeGWCache(e){if(_.fjage&&_.fjage.gateways){var t=_.fjage.gateways.indexOf(e);null!=t&&_.fjage.gateways.splice(t,1)}}_update_watch(){}addEventListener(e,t){Array.isArray(this.eventListeners[e])||(this.eventListeners[e]=[]),this.eventListeners[e].push(t)}removeEventListener(e,t){if(!this.eventListeners[e])return;let s=this.eventListeners[e].indexOf(t);s>=0&&this.eventListeners[e].splice(s,1)}addMessageListener(e){this.addEventListener("message",e)}removeMessageListener(e){this.removeEventListener("message",e)}addConnListener(e){this.addEventListener("conn",e)}removeConnListener(e){this.removeEventListener("conn",e)}getAgentID(){return this.aid}agent(e){return new h(e,!1,this)}topic(e,t){return"string"==typeof e||e instanceof String?new h(e,!0,this):e instanceof h?e.isTopic()?e:new h(e.getName()+(t?"__"+t:"")+"__ntf",!0,this):void 0}subscribe(e){e.isTopic()||(e=new h(e.getName()+"__ntf",!0,this)),this.subscriptions[e.toJSON()]=!0,this._update_watch()}unsubscribe(e){e.isTopic()||(e=new h(e.getName()+"__ntf",!0,this)),delete this.subscriptions[e.toJSON()],this._update_watch()}async agentForService(e){let t={action:"agentForService",service:e},s=await this._msgTxRx(t);if(s&&s.agentID)return new h(s.agentID,!1,this)}async agentsForService(e){let t={action:"agentsForService",service:e},s=await this._msgTxRx(t),n=[];if(!s||!Array.isArray(s.agentIDs))return n;for(var r=0;r<s.agentIDs.length;r++)n.push(new h(s.agentIDs[r],!1,this));return n}send(e){e.sender=this.aid.toJSON(),""==e.perf&&(e.__clazz__.endsWith("Req")?e.perf=c.REQUEST:e.perf=c.INFORM),this._sendEvent("txmsg",e);let t=JSON.stringify({action:"send",relay:!0,message:"###MSG###"});return t=t.replace('"###MSG###"',e._serialize()),!!this._msgTx(t)}flush(){this.queue.length=0}async request(e,t=1e3){return this.send(e),this.receive(e,t)}async receive(e,t=0){return new Promise((s=>{let n=this._getMessageFromQueue.call(this,e);if(n)return void s(n);if(0==t)return this.debug&&console.log("Receive Timeout : "+e),void s();let r,i=f(8);t>0&&(r=setTimeout((()=>{delete this.listener[i],this.debug&&console.log("Receive Timeout : "+e),s()}),t)),this.listener[i]=t=>!!this._matchMessage(e,t)&&(r&&clearTimeout(r),delete this.listener[i],s(t),!0)}))}close(){this.connector.close(),this._removeGWCache(this)}}const d={SHELL:"org.arl.fjage.shell.Services.SHELL"};function p(e,t=u){let s=e.replace(/^.*\./,"");if(p[s])return p[s];let n=class extends t{constructor(t){if(super(),this.__clazz__=e,t){const e=Object.keys(t);for(let s of e)this[s]=t[s]}}};return n.__clazz__=e,p[s]=n,n}function f(e){function t(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}let s=t();for(var n=0;n<e-1;n++)s+=t();return s}function R(e,t){if(null===t)return null;if("object"==typeof t&&"clazz"in t){let e=t.clazz;if(e.startsWith("[")&&2==e.length&&"data"in t){let e=function(e,t,s=!0){let n=_.atob(e),r=n.length,i=new Uint8Array(r);for(var o=0;o<r;o++)i[o]=n.charCodeAt(o);let a=[],l=new DataView(i.buffer);switch(t){case"[B":for(o=0;o<r;o++)a.push(l.getUint8(o));break;case"[S":for(o=0;o<r;o+=2)a.push(l.getInt16(o,s));break;case"[I":for(o=0;o<r;o+=4)a.push(l.getInt32(o,s));break;case"[J":for(o=0;o<r;o+=8)a.push(l.getInt64(o,s));break;case"[F":for(o=0;o<r;o+=4)a.push(l.getFloat32(o,s));break;case"[D":for(o=0;o<r;o+=8)a.push(l.getFloat64(o,s));break;default:return}return a}(t.data,t.clazz);e&&(t=e)}}return t}const m={};let S,_={};t||s?(_=window,Object.assign(m,{hostname:_.location.hostname,port:_.location.port,pathname:"/ws/",timeout:1e3,keepAlive:!0,queueSize:128}),S=new URL("ws://localhost"),void 0===_.fjage&&(_.fjage={}),void 0===_.fjage.gateways&&(_.fjage.gateways=[])):((()=>"undefined"!=typeof window&&"nodejs"===window.name||navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom"))||n)&&(_=global,Object.assign(m,{hostname:"localhost",port:"1100",pathname:"",timeout:1e3,keepAlive:!0,queueSize:128}),S=new URL("tcp://localhost"),_.atob=e=>Buffer.from(e,"base64").toString("binary"));const v=p("org.arl.fjage.param.ParameterReq"),N=p("org.arl.unet.DatagramReq"),A=p("org.arl.unet.DatagramNtf"),k=p("org.arl.unet.bb.BasebandSignal");Object.assign(d,{NODE_INFO:"org.arl.unet.Services.NODE_INFO",ADDRESS_RESOLUTION:"org.arl.unet.Services.ADDRESS_RESOLUTION",DATAGRAM:"org.arl.unet.Services.DATAGRAM",PHYSICAL:"org.arl.unet.Services.PHYSICAL",RANGING:"org.arl.unet.Services.RANGING",BASEBAND:"org.arl.unet.Services.BASEBAND",LINK:"org.arl.unet.Services.LINK",MAC:"org.arl.unet.Services.MAC",ROUTING:"org.arl.unet.Services.ROUTING",ROUTE_MAINTENANCE:"org.arl.unet.Services.ROUTE_MAINTENANCE",TRANSPORT:"org.arl.unet.Services.TRANSPORT",REMOTE:"org.arl.unet.Services.REMOTE",STATE_MANAGER:"org.arl.unet.Services.STATE_MANAGER"});let y={DATA:0,RANGING:1,LINK:2,REMOTE:3,MAC:4,ROUTING:5,TRANSPORT:6,ROUTE_MAINTENANCE:7,LINK2:8,USER:32,MAX:63},w={TestReportNtf:p("org.arl.unet.TestReportNtf"),AbnormalTerminationNtf:p("org.arl.unet.AbnormalTerminationNtf"),CapabilityListRsp:p("org.arl.unet.CapabilityListRsp"),CapabilityReq:p("org.arl.unet.CapabilityReq"),ClearReq:p("org.arl.unet.ClearReq"),DatagramCancelReq:p("org.arl.unet.DatagramCancelReq"),DatagramDeliveryNtf:p("org.arl.unet.DatagramDeliveryNtf"),DatagramFailureNtf:p("org.arl.unet.DatagramFailureNtf"),DatagramNtf:p("org.arl.unet.DatagramNtf"),DatagramProgressNtf:p("org.arl.unet.DatagramProgressNtf"),DatagramReq:p("org.arl.unet.DatagramReq"),ParamChangeNtf:p("org.arl.unet.ParamChangeNtf"),RefuseRsp:p("org.arl.unet.RefuseRsp"),FailureNtf:p("org.arl.unet.FailureNtf"),DatagramTraceReq:p("org.arl.unet.net.DatagramTraceReq"),RouteDiscoveryReq:p("org.arl.unet.net.RouteDiscoveryReq"),RouteTraceReq:p("org.arl.unet.net.RouteTraceReq"),RouteDiscoveryNtf:p("org.arl.unet.net.RouteDiscoveryNtf"),RouteTraceNtf:p("org.arl.unet.net.RouteTraceNtf"),FecDecodeReq:p("org.arl.unet.phy.FecDecodeReq"),RxJanusFrameNtf:p("org.arl.unet.phy.RxJanusFrameNtf"),TxJanusFrameReq:p("org.arl.unet.phy.TxJanusFrameReq"),BadFrameNtf:p("org.arl.unet.phy.BadFrameNtf"),BadRangeNtf:p("org.arl.unet.phy.BadRangeNtf"),ClearSyncReq:p("org.arl.unet.phy.ClearSyncReq"),CollisionNtf:p("org.arl.unet.phy.CollisionNtf"),RxFrameNtf:p("org.arl.unet.phy.RxFrameNtf",A),RxFrameStartNtf:p("org.arl.unet.phy.RxFrameStartNtf"),SyncInfoReq:p("org.arl.unet.phy.SyncInfoReq"),SyncInfoRsp:p("org.arl.unet.phy.SyncInfoRsp"),TxFrameNtf:p("org.arl.unet.phy.TxFrameNtf"),TxFrameReq:p("org.arl.unet.phy.TxFrameReq",N),TxFrameStartNtf:p("org.arl.unet.phy.TxFrameStartNtf"),TxRawFrameReq:p("org.arl.unet.phy.TxRawFrameReq"),AddressAllocReq:p("org.arl.unet.addr.AddressAllocReq"),AddressAllocRsp:p("org.arl.unet.addr.AddressAllocRsp"),AddressResolutionReq:p("org.arl.unet.addr.AddressResolutionReq"),AddressResolutionRsp:p("org.arl.unet.addr.AddressResolutionRsp"),BasebandSignal:p("org.arl.unet.bb.BasebandSignal"),RecordBasebandSignalReq:p("org.arl.unet.bb.RecordBasebandSignalReq"),RxBasebandSignalNtf:p("org.arl.unet.bb.RxBasebandSignalNtf",k),TxBasebandSignalReq:p("org.arl.unet.bb.TxBasebandSignalReq",k),LinkStatusNtf:p("org.arl.unet.link.LinkStatusNtf"),RangeNtf:p("org.arl.unet.localization.RangeNtf"),RangeReq:p("org.arl.unet.localization.RangeReq"),BeaconReq:p("org.arl.unet.localization.BeaconReq"),RespondReq:p("org.arl.unet.localization.RespondReq"),InterrogationNtf:p("org.arl.unet.localization.InterrogationNtf"),ReservationAcceptReq:p("org.arl.unet.mac.ReservationAcceptReq"),ReservationCancelReq:p("org.arl.unet.mac.ReservationCancelReq"),ReservationReq:p("org.arl.unet.mac.ReservationReq"),ReservationRsp:p("org.arl.unet.mac.ReservationRsp"),ReservationStatusNtf:p("org.arl.unet.mac.ReservationStatusNtf"),RxAckNtf:p("org.arl.unet.mac.RxAckNtf"),TxAckReq:p("org.arl.unet.mac.TxAckReq"),RemoteExecReq:p("org.arl.unet.remote.RemoteExecReq"),RemoteFailureNtf:p("org.arl.unet.remote.RemoteFailureNtf"),RemoteFileGetReq:p("org.arl.unet.remote.RemoteFileGetReq"),RemoteFileNtf:p("org.arl.unet.remote.RemoteFileNtf"),RemoteFilePutReq:p("org.arl.unet.remote.RemoteFilePutReq"),RemoteSuccessNtf:p("org.arl.unet.remote.RemoteSuccessNtf"),RemoteTextNtf:p("org.arl.unet.remote.RemoteTextNtf"),RemoteTextReq:p("org.arl.unet.remote.RemoteTextReq"),AddScheduledSleepReq:p("org.arl.unet.scheduler.AddScheduledSleepReq"),GetSleepScheduleReq:p("org.arl.unet.scheduler.GetSleepScheduleReq"),RemoveScheduledSleepReq:p("org.arl.unet.scheduler.RemoveScheduledSleepReq"),SleepScheduleRsp:p("org.arl.unet.scheduler.SleepScheduleRsp"),WakeFromSleepNtf:p("org.arl.unet.scheduler.WakeFromSleepNtf"),ClearStateReq:p("org.arl.unet.state.ClearStateReq"),SaveStateReq:p("org.arl.unet.state.SaveStateReq")};const b=w.AddressResolutionReq,T=w.DatagramReq,O=w.DatagramNtf,E=w.RxFrameNtf;e.AgentID=h,e.Gateway=g,e.Message=u,e.MessageClass=p,e.Performative=c,e.Protocol=y,e.Services=d,e.UnetMessages=w,e.UnetSocket=class{constructor(e,t,s=""){return(async()=>{this.gw=new g({hostname:e,port:t,path:s}),this.localProtocol=-1,this.remoteAddress=-1,this.remoteProtocol=y.DATA,this.timeout=0,this.provider=null;return(await this.gw.agentsForService(d.DATAGRAM)).forEach((e=>{this.gw.subscribe(this.gw.topic(e))})),this})()}close(){this.gw.close(),this.gw=null}isClosed(){return null==this.gw}bind(e){return(e==y.DATA||e>=y.USER&&e<=y.MAX)&&(this.localProtocol=e,!0)}unbind(){this.localProtocol=-1}isBound(){return this.localProtocol>=0}connect(e,t){return e>=0&&(t==y.DATA||t>=y.USER&&t<=y.MAX)&&(this.remoteAddress=e,this.remoteProtocol=t,!0)}disconnect(){this.remoteAddress=-1,this.remoteProtocol=0}isConnected(){return this.remoteAddress>=0}async getLocalAddress(){if(null==this.gw)return-1;const e=await this.gw.agentForService(d.NODE_INFO);if(null==e)return-1;const t=await e.get("address");return null!=t?t:-1}getLocalProtocol(){return this.localProtocol}getRemoteAddress(){return this.remoteAddress}getRemoteProtocol(){return this.remoteProtocol}setTimeout(e){e<0&&(e=0),this.timeout=e}getTimeout(){return this.timeout}async send(e,t=this.remoteAddress,s=this.remoteProtocol){if(t<0||null==this.gw)return!1;var n;if(Array.isArray(e))(n=new T).data=e,n.to=t,n.protocol=s;else{if(!(e instanceof T))return!1;n=e}let r=n.protocol;if(r!=y.DATA&&(r<y.USER||r>y.MAX))return!1;if(null==n.recipient){if(null==this.provider&&(this.provider=await this.gw.agentForService(d.TRANSPORT)),null==this.provider&&(this.provider=await this.gw.agentForService(d.ROUTING)),null==this.provider&&(this.provider=await this.gw.agentForService(d.LINK)),null==this.provider&&(this.provider=await this.gw.agentForService(d.PHYSICAL)),null==this.provider&&(this.provider=await this.gw.agentForService(d.DATAGRAM)),null==this.provider)return!1;n.recipient=this.provider}const i=await this.gw.request(n,1e3);return null!=i&&i.perf==c.AGREE}async receive(){return null==this.gw?null:await this.gw.receive((e=>{if(e.__clazz__!=O.__clazz__&&e.__clazz__!=E.__clazz__)return!1;let t=e.protocol;return(t==y.DATA||t>=y.USER)&&(this.localProtocol<0||this.localProtocol==t)}),this.timeout)}getGateway(){return this.gw}async agentForService(e){return null==this.gw?null:await this.gw.agentForService(e)}async agentsForService(e){return null==this.gw?null:await this.gw.agentsForService(e)}agent(e){return null==this.gw?null:this.gw.agent(e)}async host(e){const t=await this.agentForService(d.ADDRESS_RESOLUTION);if(null==t)return null;const s=new b(e);s.name=e,s.recipient=t;const n=await this.gw.request(s,1e3);return null!=n&&Object.prototype.hasOwnProperty.call(n,"address")?n.address:null}}}));
  //# sourceMappingURL=unetjs.min.js.map
  