text: !function(e){e.Wia=e.Wia||{},e.Wia.VERSION="1.0.0"}(this),function(e){e.Wia=e.Wia||{};var t=e.Wia;"undefined"!=typeof e.$&&(t.$=e.$),t.restApiEndpoint="https://api.wia.io/v1/",t.streamApi={protocol:"wss",host:"api.wia.io",port:3001,useSecure:!0,connectTimeout:1500,streamTimeout:15},t.clientInfo=null,t.initialize=function(e){t._initialize(e)},t._initialize=function(e){t.appKey=e.appKey||null,t.secretKey=e.secretKey||null,t.accessToken=e.accessToken||null,t.restApiEndpoint=e.restApiEndpoint||t.restApiEndpoint;for(var s in e.streamApi)e.streamApi.hasOwnProperty(s)&&(t.streamApi[s]=e.streamApi[s]);(t.secretKey||t.accessToken)&&(intervalId=setInterval(function(){t._restClient._get("whoami",{},function(e){t.clientInfo=e,clearInterval(intervalId)},function(e){console.log(e)})},1250)),t.stream.initialize()}}(this),"undefined"==typeof Paho&&(Paho={}),Paho.MQTT=function(e){function t(e,t){var s=t,n=e[t],o=n>>4,r=n&=15;t+=1;var c,u=0,f=1;do{if(t==e.length)return[null,s];c=e[t++],u+=(127&c)*f,f*=128}while(0!=(128&c));var d=t+u;if(d>e.length)return[null,s];var l=new m(o);switch(o){case h.CONNACK:var p=e[t++];1&p&&(l.sessionPresent=!0),l.returnCode=e[t++];break;case h.PUBLISH:var g=r>>1&3,_=i(e,t);t+=2;var v=a(e,t,_);t+=_,g>0&&(l.messageIdentifier=i(e,t),t+=2);var y=new Paho.MQTT.Message(e.subarray(t,d));1==(1&r)&&(y.retained=!0),8==(8&r)&&(y.duplicate=!0),y.qos=g,y.destinationName=v,l.payloadMessage=y;break;case h.PUBACK:case h.PUBREC:case h.PUBREL:case h.PUBCOMP:case h.UNSUBACK:l.messageIdentifier=i(e,t);break;case h.SUBACK:l.messageIdentifier=i(e,t),t+=2,l.returnCode=e.subarray(t,d)}return[l,d]}function s(e,t,s){return t[s++]=e>>8,t[s++]=e%256,s}function n(e,t,n,i){return i=s(t,n,i),c(e,n,i),i+t}function i(e,t){return 256*e[t]+e[t+1]}function o(e){var t=new Array(1),s=0;do{var n=e%128;e>>=7,e>0&&(n|=128),t[s++]=n}while(e>0&&4>s);return t}function r(e){for(var t=0,s=0;s<e.length;s++){var n=e.charCodeAt(s);n>2047?(n>=55296&&56319>=n&&(s++,t++),t+=3):n>127?t+=2:t++}return t}function c(e,t,s){for(var n=s,i=0;i<e.length;i++){var o=e.charCodeAt(i);if(o>=55296&&56319>=o){var r=e.charCodeAt(++i);if(isNaN(r))throw new Error(g(l.MALFORMED_UNICODE,[o,r]));o=(o-55296<<10)+(r-56320)+65536}127>=o?t[n++]=o:2047>=o?(t[n++]=o>>6&31|192,t[n++]=63&o|128):65535>=o?(t[n++]=o>>12&15|224,t[n++]=o>>6&63|128,t[n++]=63&o|128):(t[n++]=o>>18&7|240,t[n++]=o>>12&63|128,t[n++]=o>>6&63|128,t[n++]=63&o|128)}return t}function a(e,t,s){for(var n,i="",o=t;t+s>o;){var r=e[o++];if(128>r)n=r;else{var c=e[o++]-128;if(0>c)throw new Error(g(l.MALFORMED_UTF,[r.toString(16),c.toString(16),""]));if(224>r)n=64*(r-192)+c;else{var a=e[o++]-128;if(0>a)throw new Error(g(l.MALFORMED_UTF,[r.toString(16),c.toString(16),a.toString(16)]));if(240>r)n=4096*(r-224)+64*c+a;else{var u=e[o++]-128;if(0>u)throw new Error(g(l.MALFORMED_UTF,[r.toString(16),c.toString(16),a.toString(16),u.toString(16)]));if(!(248>r))throw new Error(g(l.MALFORMED_UTF,[r.toString(16),c.toString(16),a.toString(16),u.toString(16)]));n=262144*(r-240)+4096*c+64*a+u}}}n>65535&&(n-=65536,i+=String.fromCharCode(55296+(n>>10)),n=56320+(1023&n)),i+=String.fromCharCode(n)}return i}var u="@VERSION@",h={CONNECT:1,CONNACK:2,PUBLISH:3,PUBACK:4,PUBREC:5,PUBREL:6,PUBCOMP:7,SUBSCRIBE:8,SUBACK:9,UNSUBSCRIBE:10,UNSUBACK:11,PINGREQ:12,PINGRESP:13,DISCONNECT:14},f=function(e,t){for(var s in e)if(e.hasOwnProperty(s)){if(!t.hasOwnProperty(s)){var n="Unknown property, "+s+". Valid properties are:";for(var s in t)t.hasOwnProperty(s)&&(n=n+" "+s);throw new Error(n)}if(typeof e[s]!==t[s])throw new Error(g(l.INVALID_TYPE,[typeof e[s],s]))}},d=function(e,t){return function(){return e.apply(t,arguments)}},l={OK:{code:0,text:"AMQJSC0000I OK."},CONNECT_TIMEOUT:{code:1,text:"AMQJSC0001E Connect timed out."},SUBSCRIBE_TIMEOUT:{code:2,text:"AMQJS0002E Subscribe timed out."},UNSUBSCRIBE_TIMEOUT:{code:3,text:"AMQJS0003E Unsubscribe timed out."},PING_TIMEOUT:{code:4,text:"AMQJS0004E Ping timed out."},INTERNAL_ERROR:{code:5,text:"AMQJS0005E Internal error. Error Message: {0}, Stack trace: {1}"},CONNACK_RETURNCODE:{code:6,text:"AMQJS0006E Bad Connack return code:{0} {1}."},SOCKET_ERROR:{code:7,text:"AMQJS0007E Socket error:{0}."},SOCKET_CLOSE:{code:8,text:"AMQJS0008I Socket closed."},MALFORMED_UTF:{code:9,text:"AMQJS0009E Malformed UTF data:{0} {1} {2}."},UNSUPPORTED:{code:10,text:"AMQJS0010E {0} is not supported by this browser."},INVALID_STATE:{code:11,text:"AMQJS0011E Invalid state {0}."},INVALID_TYPE:{code:12,text:"AMQJS0012E Invalid type {0} for {1}."},INVALID_ARGUMENT:{code:13,text:"AMQJS0013E Invalid argument {0} for {1}."},UNSUPPORTED_OPERATION:{code:14,text:"AMQJS0014E Unsupported operation."},INVALID_STORED_DATA:{code:15,text:"AMQJS0015E Invalid data in local storage key={0} value={1}."},INVALID_MQTT_MESSAGE_TYPE:{code:16,text:"AMQJS0016E Invalid MQTT message type {0}."},MALFORMED_UNICODE:{code:17,text:"AMQJS0017E Malformed Unicode string:{0} {1}."}},p={0:"Connection Accepted",1:"Connection Refused: unacceptable protocol version",2:"Connection Refused: identifier rejected",3:"Connection Refused: server unavailable",4:"Connection Refused: bad user name or password",5:"Connection Refused: not authorized"},g=function(e,t){var s=e.text;if(t)for(var n,i,o=0;o<t.length;o++)if(n="{"+o+"}",i=s.indexOf(n),i>0){var r=s.substring(0,i),c=s.substring(i+n.length);s=r+t[o]+c}return s},_=[0,6,77,81,73,115,100,112,3],v=[0,4,77,81,84,84,4],m=function(e,t){this.type=e;for(var s in t)t.hasOwnProperty(s)&&(this[s]=t[s])};m.prototype.encode=function(){var e=(15&this.type)<<4,t=0,i=new Array,c=0;switch(void 0!=this.messageIdentifier&&(t+=2),this.type){case h.CONNECT:switch(this.mqttVersion){case 3:t+=_.length+3;break;case 4:t+=v.length+3}if(t+=r(this.clientId)+2,void 0!=this.willMessage){t+=r(this.willMessage.destinationName)+2;var a=this.willMessage.payloadBytes;a instanceof Uint8Array||(a=new Uint8Array(f)),t+=a.byteLength+2}void 0!=this.userName&&(t+=r(this.userName)+2),void 0!=this.password&&(t+=r(this.password)+2);break;case h.SUBSCRIBE:e|=2;for(var u=0;u<this.topics.length;u++)i[u]=r(this.topics[u]),t+=i[u]+2;t+=this.requestedQos.length;break;case h.UNSUBSCRIBE:e|=2;for(var u=0;u<this.topics.length;u++)i[u]=r(this.topics[u]),t+=i[u]+2;break;case h.PUBREL:e|=2;break;case h.PUBLISH:this.payloadMessage.duplicate&&(e|=8),e=e|=this.payloadMessage.qos<<1,this.payloadMessage.retained&&(e|=1),c=r(this.payloadMessage.destinationName),t+=c+2;var f=this.payloadMessage.payloadBytes;t+=f.byteLength,f instanceof ArrayBuffer?f=new Uint8Array(f):f instanceof Uint8Array||(f=new Uint8Array(f.buffer));break;case h.DISCONNECT:}var d=o(t),l=d.length+1,p=new ArrayBuffer(t+l),g=new Uint8Array(p);if(g[0]=e,g.set(d,1),this.type==h.PUBLISH)l=n(this.payloadMessage.destinationName,c,g,l);else if(this.type==h.CONNECT){switch(this.mqttVersion){case 3:g.set(_,l),l+=_.length;break;case 4:g.set(v,l),l+=v.length}var m=0;this.cleanSession&&(m=2),void 0!=this.willMessage&&(m|=4,m|=this.willMessage.qos<<3,this.willMessage.retained&&(m|=32)),void 0!=this.userName&&(m|=128),void 0!=this.password&&(m|=64),g[l++]=m,l=s(this.keepAliveInterval,g,l)}switch(void 0!=this.messageIdentifier&&(l=s(this.messageIdentifier,g,l)),this.type){case h.CONNECT:l=n(this.clientId,r(this.clientId),g,l),void 0!=this.willMessage&&(l=n(this.willMessage.destinationName,r(this.willMessage.destinationName),g,l),l=s(a.byteLength,g,l),g.set(a,l),l+=a.byteLength),void 0!=this.userName&&(l=n(this.userName,r(this.userName),g,l)),void 0!=this.password&&(l=n(this.password,r(this.password),g,l));break;case h.PUBLISH:g.set(f,l);break;case h.SUBSCRIBE:for(var u=0;u<this.topics.length;u++)l=n(this.topics[u],i[u],g,l),g[l++]=this.requestedQos[u];break;case h.UNSUBSCRIBE:for(var u=0;u<this.topics.length;u++)l=n(this.topics[u],i[u],g,l)}return p};var y=function(e,t,s){this._client=e,this._window=t,this._keepAliveInterval=1e3*s,this.isReset=!1;var n=new m(h.PINGREQ).encode(),i=function(e){return function(){return o.apply(e)}},o=function(){this.isReset?(this.isReset=!1,this._client._trace("Pinger.doPing","send PINGREQ"),this._client.socket.send(n),this.timeout=this._window.setTimeout(i(this),this._keepAliveInterval)):(this._client._trace("Pinger.doPing","Timed out"),this._client._disconnected(l.PING_TIMEOUT.code,g(l.PING_TIMEOUT)))};this.reset=function(){this.isReset=!0,this._window.clearTimeout(this.timeout),this._keepAliveInterval>0&&(this.timeout=setTimeout(i(this),this._keepAliveInterval))},this.cancel=function(){this._window.clearTimeout(this.timeout)}},I=function(e,t,s,n,i){this._window=t,s||(s=30);var o=function(e,t,s){return function(){return e.apply(t,s)}};this.timeout=setTimeout(o(n,e,i),1e3*s),this.cancel=function(){this._window.clearTimeout(this.timeout)}},w=function(t,s,n,i,o){if(!("WebSocket"in e&&null!==e.WebSocket))throw new Error(g(l.UNSUPPORTED,["WebSocket"]));if(!("localStorage"in e&&null!==e.localStorage))throw new Error(g(l.UNSUPPORTED,["localStorage"]));if(!("ArrayBuffer"in e&&null!==e.ArrayBuffer))throw new Error(g(l.UNSUPPORTED,["ArrayBuffer"]));this._trace("Paho.MQTT.Client",t,s,n,i,o),this.host=s,this.port=n,this.path=i,this.uri=t,this.clientId=o,this._localKey=s+":"+n+("/mqtt"!=i?":"+i:"")+":"+o+":",this._msg_queue=[],this._sentMessages={},this._receivedMessages={},this._notify_msg_sent={},this._message_identifier=1,this._sequence=0;for(var r in localStorage)(0==r.indexOf("Sent:"+this._localKey)||0==r.indexOf("Received:"+this._localKey))&&this.restore(r)};w.prototype.host,w.prototype.port,w.prototype.path,w.prototype.uri,w.prototype.clientId,w.prototype.socket,w.prototype.connected=!1,w.prototype.maxMessageIdentifier=65536,w.prototype.connectOptions,w.prototype.hostIndex,w.prototype.onConnectionLost,w.prototype.onMessageDelivered,w.prototype.onMessageArrived,w.prototype.traceFunction,w.prototype._msg_queue=null,w.prototype._connectTimeout,w.prototype.sendPinger=null,w.prototype.receivePinger=null,w.prototype.receiveBuffer=null,w.prototype._traceBuffer=null,w.prototype._MAX_TRACE_ENTRIES=100,w.prototype.connect=function(e){var t=this._traceMask(e,"password");if(this._trace("Client.connect",t,this.socket,this.connected),this.connected)throw new Error(g(l.INVALID_STATE,["already connected"]));if(this.socket)throw new Error(g(l.INVALID_STATE,["already connected"]));this.connectOptions=e,e.uris?(this.hostIndex=0,this._doConnect(e.uris[0])):this._doConnect(this.uri)},w.prototype.subscribe=function(e,t){if(this._trace("Client.subscribe",e,t),!this.connected)throw new Error(g(l.INVALID_STATE,["not connected"]));var s=new m(h.SUBSCRIBE);s.topics=[e],void 0!=t.qos?s.requestedQos=[t.qos]:s.requestedQos=[0],t.onSuccess&&(s.onSuccess=function(e){t.onSuccess({invocationContext:t.invocationContext,grantedQos:e})}),t.onFailure&&(s.onFailure=function(e){t.onFailure({invocationContext:t.invocationContext,errorCode:e})}),t.timeout&&(s.timeOut=new I(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:l.SUBSCRIBE_TIMEOUT.code,errorMessage:g(l.SUBSCRIBE_TIMEOUT)}])),this._requires_ack(s),this._schedule_message(s)},w.prototype.unsubscribe=function(e,t){if(this._trace("Client.unsubscribe",e,t),!this.connected)throw new Error(g(l.INVALID_STATE,["not connected"]));var s=new m(h.UNSUBSCRIBE);s.topics=[e],t.onSuccess&&(s.callback=function(){t.onSuccess({invocationContext:t.invocationContext})}),t.timeout&&(s.timeOut=new I(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:l.UNSUBSCRIBE_TIMEOUT.code,errorMessage:g(l.UNSUBSCRIBE_TIMEOUT)}])),this._requires_ack(s),this._schedule_message(s)},w.prototype.send=function(e){if(this._trace("Client.send",e),!this.connected)throw new Error(g(l.INVALID_STATE,["not connected"]));wireMessage=new m(h.PUBLISH),wireMessage.payloadMessage=e,e.qos>0?this._requires_ack(wireMessage):this.onMessageDelivered&&(this._notify_msg_sent[wireMessage]=this.onMessageDelivered(wireMessage.payloadMessage)),this._schedule_message(wireMessage)},w.prototype.disconnect=function(){if(this._trace("Client.disconnect"),!this.socket)throw new Error(g(l.INVALID_STATE,["not connecting or connected"]));wireMessage=new m(h.DISCONNECT),this._notify_msg_sent[wireMessage]=d(this._disconnected,this),this._schedule_message(wireMessage)},w.prototype.getTraceLog=function(){if(null!==this._traceBuffer){this._trace("Client.getTraceLog",new Date),this._trace("Client.getTraceLog in flight messages",this._sentMessages.length);for(var e in this._sentMessages)this._trace("_sentMessages ",e,this._sentMessages[e]);for(var e in this._receivedMessages)this._trace("_receivedMessages ",e,this._receivedMessages[e]);return this._traceBuffer}},w.prototype.startTrace=function(){null===this._traceBuffer&&(this._traceBuffer=[]),this._trace("Client.startTrace",new Date,u)},w.prototype.stopTrace=function(){delete this._traceBuffer},w.prototype._doConnect=function(e){if(this.connectOptions.useSSL){var t=e.split(":");t[0]="wss",e=t.join(":")}this.connected=!1,this.connectOptions.mqttVersion<4?this.socket=new WebSocket(e,["mqttv3.1"]):this.socket=new WebSocket(e,["mqtt"]),this.socket.binaryType="arraybuffer",this.socket.onopen=d(this._on_socket_open,this),this.socket.onmessage=d(this._on_socket_message,this),this.socket.onerror=d(this._on_socket_error,this),this.socket.onclose=d(this._on_socket_close,this),this.sendPinger=new y(this,window,this.connectOptions.keepAliveInterval),this.receivePinger=new y(this,window,this.connectOptions.keepAliveInterval),this._connectTimeout=new I(this,window,this.connectOptions.timeout,this._disconnected,[l.CONNECT_TIMEOUT.code,g(l.CONNECT_TIMEOUT)])},w.prototype._schedule_message=function(e){this._msg_queue.push(e),this.connected&&this._process_queue()},w.prototype.store=function(e,t){var s={type:t.type,messageIdentifier:t.messageIdentifier,version:1};switch(t.type){case h.PUBLISH:t.pubRecReceived&&(s.pubRecReceived=!0),s.payloadMessage={};for(var n="",i=t.payloadMessage.payloadBytes,o=0;o<i.length;o++)i[o]<=15?n=n+"0"+i[o].toString(16):n+=i[o].toString(16);s.payloadMessage.payloadHex=n,s.payloadMessage.qos=t.payloadMessage.qos,s.payloadMessage.destinationName=t.payloadMessage.destinationName,t.payloadMessage.duplicate&&(s.payloadMessage.duplicate=!0),t.payloadMessage.retained&&(s.payloadMessage.retained=!0),0==e.indexOf("Sent:")&&(void 0===t.sequence&&(t.sequence=++this._sequence),s.sequence=t.sequence);break;default:throw Error(g(l.INVALID_STORED_DATA,[key,s]))}localStorage.setItem(e+this._localKey+t.messageIdentifier,JSON.stringify(s))},w.prototype.restore=function(e){var t=localStorage.getItem(e),s=JSON.parse(t),n=new m(s.type,s);switch(s.type){case h.PUBLISH:for(var i=s.payloadMessage.payloadHex,o=new ArrayBuffer(i.length/2),r=new Uint8Array(o),c=0;i.length>=2;){var a=parseInt(i.substring(0,2),16);i=i.substring(2,i.length),r[c++]=a}var u=new Paho.MQTT.Message(r);u.qos=s.payloadMessage.qos,u.destinationName=s.payloadMessage.destinationName,s.payloadMessage.duplicate&&(u.duplicate=!0),s.payloadMessage.retained&&(u.retained=!0),n.payloadMessage=u;break;default:throw Error(g(l.INVALID_STORED_DATA,[e,t]))}0==e.indexOf("Sent:"+this._localKey)?(n.payloadMessage.duplicate=!0,this._sentMessages[n.messageIdentifier]=n):0==e.indexOf("Received:"+this._localKey)&&(this._receivedMessages[n.messageIdentifier]=n)},w.prototype._process_queue=function(){for(var e=null,t=this._msg_queue.reverse();e=t.pop();)this._socket_send(e),this._notify_msg_sent[e]&&(this._notify_msg_sent[e](),delete this._notify_msg_sent[e])},w.prototype._requires_ack=function(e){var t=Object.keys(this._sentMessages).length;if(t>this.maxMessageIdentifier)throw Error("Too many messages:"+t);for(;void 0!==this._sentMessages[this._message_identifier];)this._message_identifier++;e.messageIdentifier=this._message_identifier,this._sentMessages[e.messageIdentifier]=e,e.type===h.PUBLISH&&this.store("Sent:",e),this._message_identifier===this.maxMessageIdentifier&&(this._message_identifier=1)},w.prototype._on_socket_open=function(){var e=new m(h.CONNECT,this.connectOptions);e.clientId=this.clientId,this._socket_send(e)},w.prototype._on_socket_message=function(e){this._trace("Client._on_socket_message",e.data);for(var t=this._deframeMessages(e.data),s=0;s<t.length;s+=1)this._handleMessage(t[s])},w.prototype._deframeMessages=function(e){var s=new Uint8Array(e);if(this.receiveBuffer){var n=new Uint8Array(this.receiveBuffer.length+s.length);n.set(this.receiveBuffer),n.set(s,this.receiveBuffer.length),s=n,delete this.receiveBuffer}try{for(var i=0,o=[];i<s.length;){var r=t(s,i),c=r[0];if(i=r[1],null===c)break;o.push(c)}i<s.length&&(this.receiveBuffer=s.subarray(i))}catch(a){return void this._disconnected(l.INTERNAL_ERROR.code,g(l.INTERNAL_ERROR,[a.message,a.stack.toString()]))}return o},w.prototype._handleMessage=function(e){this._trace("Client._handleMessage",e);try{switch(e.type){case h.CONNACK:if(this._connectTimeout.cancel(),this.connectOptions.cleanSession){for(var t in this._sentMessages){var s=this._sentMessages[t];localStorage.removeItem("Sent:"+this._localKey+s.messageIdentifier)}this._sentMessages={};for(var t in this._receivedMessages){var n=this._receivedMessages[t];localStorage.removeItem("Received:"+this._localKey+n.messageIdentifier)}this._receivedMessages={}}if(0!==e.returnCode){this._disconnected(l.CONNACK_RETURNCODE.code,g(l.CONNACK_RETURNCODE,[e.returnCode,p[e.returnCode]]));break}this.connected=!0,this.connectOptions.uris&&(this.hostIndex=this.connectOptions.uris.length);var i=new Array;for(var o in this._sentMessages)this._sentMessages.hasOwnProperty(o)&&i.push(this._sentMessages[o]);for(var i=i.sort(function(e,t){return e.sequence-t.sequence}),r=0,c=i.length;c>r;r++){var s=i[r];if(s.type==h.PUBLISH&&s.pubRecReceived){var a=new m(h.PUBREL,{messageIdentifier:s.messageIdentifier});this._schedule_message(a)}else this._schedule_message(s)}this.connectOptions.onSuccess&&this.connectOptions.onSuccess({invocationContext:this.connectOptions.invocationContext}),this._process_queue();break;case h.PUBLISH:this._receivePublish(e);break;case h.PUBACK:var s=this._sentMessages[e.messageIdentifier];s&&(delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(s.payloadMessage));break;case h.PUBREC:var s=this._sentMessages[e.messageIdentifier];if(s){s.pubRecReceived=!0;var a=new m(h.PUBREL,{messageIdentifier:e.messageIdentifier});this.store("Sent:",s),this._schedule_message(a)}break;case h.PUBREL:var n=this._receivedMessages[e.messageIdentifier];localStorage.removeItem("Received:"+this._localKey+e.messageIdentifier),n&&(this._receiveMessage(n),delete this._receivedMessages[e.messageIdentifier]);var u=new m(h.PUBCOMP,{messageIdentifier:e.messageIdentifier});this._schedule_message(u);break;case h.PUBCOMP:var s=this._sentMessages[e.messageIdentifier];delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(s.payloadMessage);break;case h.SUBACK:var s=this._sentMessages[e.messageIdentifier];s&&(s.timeOut&&s.timeOut.cancel(),128===e.returnCode[0]?s.onFailure&&s.onFailure(e.returnCode):s.onSuccess&&s.onSuccess(e.returnCode),delete this._sentMessages[e.messageIdentifier]);break;case h.UNSUBACK:var s=this._sentMessages[e.messageIdentifier];s&&(s.timeOut&&s.timeOut.cancel(),s.callback&&s.callback(),delete this._sentMessages[e.messageIdentifier]);break;case h.PINGRESP:this.sendPinger.reset();break;case h.DISCONNECT:this._disconnected(l.INVALID_MQTT_MESSAGE_TYPE.code,g(l.INVALID_MQTT_MESSAGE_TYPE,[e.type]));break;default:this._disconnected(l.INVALID_MQTT_MESSAGE_TYPE.code,g(l.INVALID_MQTT_MESSAGE_TYPE,[e.type]))}}catch(f){return void this._disconnected(l.INTERNAL_ERROR.code,g(l.INTERNAL_ERROR,[f.message,f.stack.toString()]))}},w.prototype._on_socket_error=function(e){this._disconnected(l.SOCKET_ERROR.code,g(l.SOCKET_ERROR,[e.data]))},w.prototype._on_socket_close=function(){this._disconnected(l.SOCKET_CLOSE.code,g(l.SOCKET_CLOSE))},w.prototype._socket_send=function(e){if(1==e.type){var t=this._traceMask(e,"password");this._trace("Client._socket_send",t)}else this._trace("Client._socket_send",e);this.socket.send(e.encode()),this.sendPinger.reset()},w.prototype._receivePublish=function(e){switch(e.payloadMessage.qos){case"undefined":case 0:this._receiveMessage(e);break;case 1:var t=new m(h.PUBACK,{messageIdentifier:e.messageIdentifier});this._schedule_message(t),this._receiveMessage(e);break;case 2:this._receivedMessages[e.messageIdentifier]=e,this.store("Received:",e);var s=new m(h.PUBREC,{messageIdentifier:e.messageIdentifier});this._schedule_message(s);break;default:throw Error("Invaild qos="+wireMmessage.payloadMessage.qos)}},w.prototype._receiveMessage=function(e){this.onMessageArrived&&this.onMessageArrived(e.payloadMessage)},w.prototype._disconnected=function(e,t){this._trace("Client._disconnected",e,t),this.sendPinger.cancel(),this.receivePinger.cancel(),this._connectTimeout&&this._connectTimeout.cancel(),this._msg_queue=[],this._notify_msg_sent={},this.socket&&(this.socket.onopen=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.onclose=null,1===this.socket.readyState&&this.socket.close(),delete this.socket),this.connectOptions.uris&&this.hostIndex<this.connectOptions.uris.length-1?(this.hostIndex++,this._doConnect(this.connectOptions.uris[this.hostIndex])):(void 0===e&&(e=l.OK.code,t=g(l.OK)),this.connected?(this.connected=!1,this.onConnectionLost&&this.onConnectionLost({errorCode:e,errorMessage:t})):4===this.connectOptions.mqttVersion&&this.connectOptions.mqttVersionExplicit===!1?(this._trace("Failed to connect V4, dropping back to V3"),this.connectOptions.mqttVersion=3,this.connectOptions.uris?(this.hostIndex=0,this._doConnect(this.connectOptions.uris[0])):this._doConnect(this.uri)):this.connectOptions.onFailure&&this.connectOptions.onFailure({invocationContext:this.connectOptions.invocationContext,errorCode:e,errorMessage:t}))},w.prototype._trace=function(){if(this.traceFunction){for(var e in arguments)"undefined"!=typeof arguments[e]&&(arguments[e]=JSON.stringify(arguments[e]));var t=Array.prototype.slice.call(arguments).join("");this.traceFunction({severity:"Debug",message:t})}if(null!==this._traceBuffer)for(var e=0,s=arguments.length;s>e;e++)this._traceBuffer.length==this._MAX_TRACE_ENTRIES&&this._traceBuffer.shift(),0===e?this._traceBuffer.push(arguments[e]):"undefined"==typeof arguments[e]?this._traceBuffer.push(arguments[e]):this._traceBuffer.push("  "+JSON.stringify(arguments[e]))},w.prototype._traceMask=function(e,t){var s={};for(var n in e)e.hasOwnProperty(n)&&(n==t?s[n]="******":s[n]=e[n]);return s};var E=function(e,t,s,n){var i;if("string"!=typeof e)throw new Error(g(l.INVALID_TYPE,[typeof e,"host"]));if(2==arguments.length){n=t,i=e;var o=i.match(/^(wss?):\/\/((\[(.+)\])|([^\/]+?))(:(\d+))?(\/.*)$/);if(!o)throw new Error(g(l.INVALID_ARGUMENT,[e,"host"]));e=o[4]||o[2],t=parseInt(o[7]),s=o[8]}else{if(3==arguments.length&&(n=s,s="/mqtt"),"number"!=typeof t||0>t)throw new Error(g(l.INVALID_TYPE,[typeof t,"port"]));if("string"!=typeof s)throw new Error(g(l.INVALID_TYPE,[typeof s,"path"]));var r=-1!=e.indexOf(":")&&"["!=e.slice(0,1)&&"]"!=e.slice(-1);i="ws://"+(r?"["+e+"]":e)+":"+t+s}for(var c=0,a=0;a<n.length;a++){var u=n.charCodeAt(a);u>=55296&&56319>=u&&a++,c++}if("string"!=typeof n||c>65535)throw new Error(g(l.INVALID_ARGUMENT,[n,"clientId"]));var h=new w(i,e,t,s,n);this._getHost=function(){return e},this._setHost=function(){throw new Error(g(l.UNSUPPORTED_OPERATION))},this._getPort=function(){return t},this._setPort=function(){throw new Error(g(l.UNSUPPORTED_OPERATION))},this._getPath=function(){return s},this._setPath=function(){throw new Error(g(l.UNSUPPORTED_OPERATION))},this._getURI=function(){return i},this._setURI=function(){throw new Error(g(l.UNSUPPORTED_OPERATION))},this._getClientId=function(){return h.clientId},this._setClientId=function(){throw new Error(g(l.UNSUPPORTED_OPERATION))},this._getOnConnectionLost=function(){return h.onConnectionLost},this._setOnConnectionLost=function(e){if("function"!=typeof e)throw new Error(g(l.INVALID_TYPE,[typeof e,"onConnectionLost"]));h.onConnectionLost=e},this._getOnMessageDelivered=function(){return h.onMessageDelivered},this._setOnMessageDelivered=function(e){if("function"!=typeof e)throw new Error(g(l.INVALID_TYPE,[typeof e,"onMessageDelivered"]));h.onMessageDelivered=e},this._getOnMessageArrived=function(){return h.onMessageArrived},this._setOnMessageArrived=function(e){if("function"!=typeof e)throw new Error(g(l.INVALID_TYPE,[typeof e,"onMessageArrived"]));h.onMessageArrived=e},this._getTrace=function(){return h.traceFunction},this._setTrace=function(e){if("function"!=typeof e)throw new Error(g(l.INVALID_TYPE,[typeof e,"onTrace"]));h.traceFunction=e},this.connect=function(e){if(e=e||{},f(e,{timeout:"number",userName:"string",password:"string",willMessage:"object",keepAliveInterval:"number",cleanSession:"boolean",useSSL:"boolean",invocationContext:"object",onSuccess:"function",onFailure:"function",hosts:"object",ports:"object",mqttVersion:"number",mqttVersionExplicit:"boolean",uris:"object"}),void 0===e.keepAliveInterval&&(e.keepAliveInterval=60),e.mqttVersion>4||e.mqttVersion<3)throw new Error(g(l.INVALID_ARGUMENT,[e.mqttVersion,"connectOptions.mqttVersion"]));if(void 0===e.mqttVersion?(e.mqttVersionExplicit=!1,e.mqttVersion=4):e.mqttVersionExplicit=!0,void 0!==e.password&&void 0===e.userName)throw new Error(g(l.INVALID_ARGUMENT,[e.password,"connectOptions.password"]));if(e.willMessage){if(!(e.willMessage instanceof b))throw new Error(g(l.INVALID_TYPE,[e.willMessage,"connectOptions.willMessage"]));if(e.willMessage.stringPayload,"undefined"==typeof e.willMessage.destinationName)throw new Error(g(l.INVALID_TYPE,[typeof e.willMessage.destinationName,"connectOptions.willMessage.destinationName"]))}if("undefined"==typeof e.cleanSession&&(e.cleanSession=!0),e.hosts){if(!(e.hosts instanceof Array))throw new Error(g(l.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));if(e.hosts.length<1)throw new Error(g(l.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));for(var t=!1,n=0;n<e.hosts.length;n++){if("string"!=typeof e.hosts[n])throw new Error(g(l.INVALID_TYPE,[typeof e.hosts[n],"connectOptions.hosts["+n+"]"]));if(/^(wss?):\/\/((\[(.+)\])|([^\/]+?))(:(\d+))?(\/.*)$/.test(e.hosts[n])){if(0==n)t=!0;else if(!t)throw new Error(g(l.INVALID_ARGUMENT,[e.hosts[n],"connectOptions.hosts["+n+"]"]))}else if(t)throw new Error(g(l.INVALID_ARGUMENT,[e.hosts[n],"connectOptions.hosts["+n+"]"]))}if(t)e.uris=e.hosts;else{if(!e.ports)throw new Error(g(l.INVALID_ARGUMENT,[e.ports,"connectOptions.ports"]));if(!(e.ports instanceof Array))throw new Error(g(l.INVALID_ARGUMENT,[e.ports,"connectOptions.ports"]));if(e.hosts.length!=e.ports.length)throw new Error(g(l.INVALID_ARGUMENT,[e.ports,"connectOptions.ports"]));e.uris=[];for(var n=0;n<e.hosts.length;n++){if("number"!=typeof e.ports[n]||e.ports[n]<0)throw new Error(g(l.INVALID_TYPE,[typeof e.ports[n],"connectOptions.ports["+n+"]"]));var o=e.hosts[n],r=e.ports[n],c=-1!=o.indexOf(":");i="ws://"+(c?"["+o+"]":o)+":"+r+s,e.uris.push(i)}}}h.connect(e)},this.subscribe=function(e,t){if("string"!=typeof e)throw new Error("Invalid argument:"+e);if(t=t||{},f(t,{qos:"number",invocationContext:"object",onSuccess:"function",onFailure:"function",timeout:"number"}),t.timeout&&!t.onFailure)throw new Error("subscribeOptions.timeout specified with no onFailure callback.");if("undefined"!=typeof t.qos&&0!==t.qos&&1!==t.qos&&2!==t.qos)throw new Error(g(l.INVALID_ARGUMENT,[t.qos,"subscribeOptions.qos"]));h.subscribe(e,t)},this.unsubscribe=function(e,t){if("string"!=typeof e)throw new Error("Invalid argument:"+e);if(t=t||{},f(t,{invocationContext:"object",onSuccess:"function",onFailure:"function",timeout:"number"}),t.timeout&&!t.onFailure)throw new Error("unsubscribeOptions.timeout specified with no onFailure callback.");h.unsubscribe(e,t)},this.send=function(e,t,s,n){var i;if(0==arguments.length)throw new Error("Invalid argument.length");if(1==arguments.length){if(!(e instanceof b)&&"string"!=typeof e)throw new Error("Invalid argument:"+typeof e);if(i=e,"undefined"==typeof i.destinationName)throw new Error(g(l.INVALID_ARGUMENT,[i.destinationName,"Message.destinationName"]));h.send(i)}else i=new b(t),i.destinationName=e,arguments.length>=3&&(i.qos=s),arguments.length>=4&&(i.retained=n),h.send(i)},this.disconnect=function(){h.disconnect()},this.getTraceLog=function(){return h.getTraceLog()},this.startTrace=function(){h.startTrace()},this.stopTrace=function(){h.stopTrace()},this.isConnected=function(){return h.connected}};E.prototype={get host(){return this._getHost()},set host(e){this._setHost(e)},get port(){return this._getPort()},set port(e){this._setPort(e)},get path(){return this._getPath()},set path(e){this._setPath(e)},get clientId(){return this._getClientId()},set clientId(e){this._setClientId(e)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(e){this._setOnConnectionLost(e)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(e){this._setOnMessageDelivered(e)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(e){this._setOnMessageArrived(e)},get trace(){return this._getTrace()},set trace(e){this._setTrace(e)}};var b=function(e){var t;if(!("string"==typeof e||e instanceof ArrayBuffer||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array))throw g(l.INVALID_ARGUMENT,[e,"newPayload"]);t=e,this._getPayloadString=function(){return"string"==typeof t?t:a(t,0,t.length)},this._getPayloadBytes=function(){if("string"==typeof t){var e=new ArrayBuffer(r(t)),s=new Uint8Array(e);return c(t,s,0),s}return t};var s=void 0;this._getDestinationName=function(){return s},this._setDestinationName=function(e){if("string"!=typeof e)throw new Error(g(l.INVALID_ARGUMENT,[e,"newDestinationName"]));s=e};var n=0;this._getQos=function(){return n},this._setQos=function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);n=e};var i=!1;this._getRetained=function(){return i},this._setRetained=function(e){if("boolean"!=typeof e)throw new Error(g(l.INVALID_ARGUMENT,[e,"newRetained"]));i=e};var o=!1;this._getDuplicate=function(){return o},this._setDuplicate=function(e){o=e}};return b.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(e){this._setDestinationName(e)},get qos(){return this._getQos()},set qos(e){this._setQos(e)},get retained(){return this._getRetained()},set retained(e){this._setRetained(e)},get duplicate(){return this._getDuplicate()},set duplicate(e){this._setDuplicate(e)}},{Client:E,Message:b}}(window),function(e){function t(e){return n.secretKey&&e.setRequestHeader("Authorization","Bearer "+n.secretKey),n.accessToken&&e.setRequestHeader("Authorization","Bearer "+n.accessToken),n.appKey&&e.setRequestHeader("x-app-key",n.appKey),e}function s(e){var t=[];for(var s in e)e.hasOwnProperty(s)&&t.push(encodeURIComponent(s)+"="+encodeURIComponent(e[s]));return t.join("&")}e.Wia=e.Wia||{};var n=e.Wia;n._restClient=n._restClient||{},n._restClient._get=function(e,i,o,r){var c=new XMLHttpRequest,a=n.restApiEndpoint+e;i&&(a+="?"+s(i)),c.open("get",a,!0),c=t(c),c.responseType="json",c.onload=function(){var e=c.status;200==e?o(c.response):r({status:c.status,response:c.response})},c.send()},n._restClient._post=function(e,s,i,o){var r=new XMLHttpRequest;r.open("post",n.restApiEndpoint+e,!0),r=t(r),r.setRequestHeader("Content-Type","application/json;charset=UTF-8"),r.responseType="json",r.onload=function(){var e=r.status;200==e||201==e?i(r.response):o({status:r.status,response:r.response})},r.send(JSON.stringify(s||{}))},n._restClient._put=function(e,s,i,o){
  var r=new XMLHttpRequest;r.open("put",n.restApiEndpoint+e,!0),r=t(r),r.setRequestHeader("Content-Type","application/json;charset=UTF-8"),r.responseType="json",r.onload=function(){var e=r.status;200==e||201==e?i(r.response):o({status:r.status,response:r.response})},r.send(JSON.stringify(s||{}))},n._restClient._delete=function(e,s,i){var o=new XMLHttpRequest;o.open("delete",n.restApiEndpoint+e,!0),o=t(o),o.responseType="json",o.onload=function(){var e=o.status;200==e?s(o.response):i({status:o.status,response:o.response})},o.send()}}(this),function(e){e.Wia=e.Wia||{};var t=e.Wia;t.stream=t.stream||{},t.stream.connected=!1;var s={},n=null;t.stream.initialize=function(){console.log(t.streamApi),n=new Paho.MQTT.Client(t.streamApi.host,parseInt(t.streamApi.port),"/",""),n.onConnectionLost=function(e){t.stream.connected=!1,t.stream.onConnectionLost&&t.stream.onConnectionLost(e),setTimeout(function(){console.log("Attempting reconnect..."),n.connect({onSuccess:function(){console.log("Reconnected.");for(var e in s)s.hasOwnProperty(e)&&n.subscribe(e)},onFailure:function(){console.log("Could not reconnect.")}},t.streamApi.connectTimeout)})},n.onMessageArrived=function(e){var t=e.destinationName;try{if(0===t.indexOf("devices")){var n=t.match("devices/(.*?)/(.*)");if(n){var i=n[1],o=n[2],r=e.payloadString,c=null;if(c=r&&r.length>0?JSON.parse(r):{},o.indexOf("/")>=0){var a=o.match("(.*?)/(.*)");c.type=a[1]}else c.type=o;s["devices/"+i+"/#"]&&"function"==typeof s["devices/"+i+"/#"]&&s["devices/"+i+"/#"](c),s[t]&&"function"==typeof s[t]&&s[t](c),0==o.indexOf("events")&&"function"==typeof s["devices/"+i+"/events/+"]?s["devices/"+i+"/events/+"](c):0==o.indexOf("logs")&&"function"==typeof s["devices/"+i+"/logs/+"]?s["devices/"+i+"/logs/+"](c):0==o.indexOf("locations")&&"function"==typeof s["devices/"+i+"/locations/+"]?s["devices/"+i+"/locations/+"](c):0==o.indexOf("sensors")&&"function"==typeof s["devices/"+i+"/sensors/+"]?s["devices/"+i+"/sensors/+"](c):0==o.indexOf("commands")&&exec(c.command,function(e,t,s){e&&console.log(e),t&&console.log(t),s&&console.log(s)})}}}catch(u){console.log(u)}},n.onMessageDelivered=function(e){t.stream.onMessageDelivered&&t.stream.onMessageDelivered(e)}},t.stream.connect=function(e){e||(e={}),console.log(t.streamApi),t.secretKey||t.appKey?n.connect({timeout:t.streamApi.streamTimeout,userName:t.secretKey||t.appKey,password:" ",useSSL:t.streamApi.useSecure,onSuccess:function(){t.stream.connected=!0,e&&e.onSuccess&&e.onSuccess()},onFailure:function(s){t.stream.connected=!1,e&&e.onFailure&&e.onFailure(s)}}):t.stream.connected=!1},t.stream.disconnect=function(){t.stream.connected=!1,n.disconnect()},t.stream.subscribe=function(e,i){s[e]=i,t.stream.connected&&n.subscribe(e,{qos:0})},t.stream.unsubscribe=function(e,i){delete s[e],t.stream.connected&&n.unsubscribe(e)},t.stream.unsubscribeAll=function(e,i){for(var e in s)s.hasOwnProperty(e)&&(t.stream.connected&&n.unsubscribe(e),delete s[e])},t.stream.publish=function(e,t,s){var i=new Paho.MQTT.Message(t);i.destinationName=e,n.send(i)}}(this),function(e){e.Wia=e.Wia||{};var t=e.Wia;t.customers=t.customers||{},t.customers.create=function(e,s,n){t._restClient._post("customers",e,function(e){s(e)},function(e){n(e)})},t.customers.retrieve=function(e,s,n){t._restClient._get("customers/"+e,{},function(e){s(e)},function(e){n(e)})},t.customers.update=function(e,s,n,i){t._restClient._put("customers/"+e,s,function(e){n(e)},function(e){i(e)})},t.customers["delete"]=function(e,s,n){t._restClient._delete("customers/"+e,function(e){s(e)},function(e){n(e)})},t.customers.list=function(e,s,n){t._restClient._get("customers",e,function(e){s(e)},function(e){n(e)})},t.customers.signup=function(e,s,n){t._restClient._post("customers/signup",e,function(e){s(e)},function(e){n(e)})},t.customers.login=function(e,s,n){e.scope="customer",e.grantType="password",t._restClient._post("auth/token",e,function(e){t.accessToken=e.accessToken,s(e)},function(e){n(e)})}}(this),function(e){e.Wia=e.Wia||{};var t=e.Wia;t.devices=t.devices||{},t.devices.create=function(e,s,n){t._restClient._post("devices",e,function(e){s(e)},function(e){n(e)})},t.devices.retrieve=function(e,s,n){t._restClient._get("devices/"+e,{},function(e){s(e)},function(e){n(e)})},t.devices.update=function(e,s,n,i){t._restClient._put("devices/"+e,s,function(e){n(e)},function(e){i(e)})},t.devices["delete"]=function(e,s,n){t._restClient._delete("devices/"+e,function(e){s(e)},function(e){n(e)})},t.devices.list=function(e,s,n){t._restClient._get("devices",e,function(e){s(e.devices,e.count)},function(e){n(e)})},t.devices.subscribe=function(e,s){"object"==typeof e?e.id&&t.stream.subscribe("devices/"+e.id+"/#",s):t.stream.subscribe("devices/"+e+"/#",s)},t.devices.unsubscribe=function(e,s){"object"==typeof e?e.id&&t.stream.unsubscribe("devices/"+e.id+"/#",s):t.stream.unsubscribe("devices/"+e+"/#",s)}}(this),function(e){e.Wia=e.Wia||{};var t=e.Wia;t.events=t.events||{},t.events.subscribe=function(e,s){e.name?t.stream.subscribe("devices/"+e.device+"/events/"+e.name,s):t.stream.subscribe("devices/"+e.device+"/events/+",s)},t.events.unsubscribe=function(e,s){e.name?t.stream.unsubscribe("devices/"+e.device+"/events/"+e.name,s):t.stream.unsubscribe("devices/"+e.device+"/events/+",s)},t.events.publish=function(e,s){t.clientInfo&&t.clientInfo.device&&t.stream&&t.stream.connected?t.stream.publish("devices/"+t.clientInfo.device.id+"/events/"+e.name,e?JSON.stringify(e):null,s):t._restClient._post("events",e,function(e){s(e)},function(e){s(e)})},t.events.list=function(e,s,n){t._restClient._get("events",e,function(e){s(e.events,e.count)},function(e){n(e)})}}(this),function(e){e.Wia=e.Wia||{};var t=e.Wia;t.functions=t.functions||{},t.functions.list=function(e,s,n){t._restClient._get("functions",e,function(e){s(e.functions,e.count)},function(e){n(e)})},t.functions.call=function(e,s,n){if(!e)return n({message:"No options specified."});var i=null,o=null;"object"==typeof e?(i=e.id,o=e.device):i=e,o&&t.stream&&t.stream.connected?t.stream.publish("devices/"+o+"/functions/"+i+"/call",e.data?JSON.stringify(e.data):null,s):t._restClient._post("functions/"+i+"/call",e,function(e){s(e)},function(e){n(e)})}}(this),function(e){e.Wia=e.Wia||{};var t=e.Wia;t.locations=t.locations||{},t.locations.subscribe=function(e,s){t.stream.subscribe("devices/"+e.device+"/locations",s)},t.locations.unsubscribe=function(e,s){t.stream.unsubscribe("devices/"+e.device+"/locations",s)},t.locations.publish=function(e,s){t.clientInfo&&t.clientInfo.device&&t.stream&&t.stream.connected?t.stream.publish("devices/"+t.clientInfo.device.id+"/locations/",e?JSON.stringify(e):null,s):t._restClient._post("events",e,function(e){s(e)},function(e){s(e)})},t.locations.list=function(e,s,n){t._restClient._get("locations",e,function(e){s(e.locations,e.count)},function(e){n(e)})}}(this),function(e){e.Wia=e.Wia||{};var t=e.Wia;t.logs=t.logs||{},t.logs.subscribe=function(e,s){e.name?t.stream.subscribe("devices/"+e.device+"/logs/"+e.level,s):t.stream.subscribe("devices/"+e.device+"/logs/+",s)},t.logs.unsubscribe=function(e,s){e.name?t.stream.unsubscribe("devices/"+e.device+"/logs/"+e.level,s):t.stream.unsubscribe("devices/"+e.device+"/logs/+",s)},t.logs.publish=function(e,s){t.clientInfo&&t.clientInfo.device&&t.stream&&t.stream.connected?t.stream.publish("devices/"+t.clientInfo.device.id+"/logs/"+e.level,e?JSON.stringify(e):null,s):t._restClient._post("events",e,function(e){s(e)},function(e){s(e)})},t.logs.list=function(e,s,n){t._restClient._get("logs",e,function(e){s(e.logs,e.count)},function(e){n(e)})}}(this),function(e){e.Wia=e.Wia||{};var t=e.Wia;t.organisations=t.organisations||{},t.organisations.retrieve=function(e,s,n){t._restClient._get("organisations/"+e,{},function(e){s(e)},function(e){n(e)})}}(this),function(e){e.Wia=e.Wia||{};var t=e.Wia;t.sensors=t.sensors||{},t.sensors.subscribe=function(e,s){e.name?t.stream.subscribe("devices/"+e.device+"/sensors/"+e.name,s):t.stream.subscribe("devices/"+e.device+"/sensors/+",s)},t.sensors.unsubscribe=function(e,s){e.name?t.stream.unsubscribe("devices/"+e.device+"/sensors/"+e.name,s):t.stream.unsubscribe("devices/"+e.device+"/sensors/+",s)},t.sensors.publish=function(e,s){t.clientInfo&&t.clientInfo.device&&t.stream&&t.stream.connected?t.stream.publish("devices/"+t.clientInfo.device.id+"/sensors/"+e.name,e?JSON.stringify(e):null,s):t._restClient._post("events",e,function(e){s(e)},function(e){s(e)})},t.sensors.list=function(e,s,n){t._restClient._get("sensors",e,function(e){s(e.sensors,e.count)},function(e){n(e)})}}(this),function(e){e.Wia=e.Wia||{};var t=e.Wia;t.users=t.users||{},t.users.retrieve=function(e,s,n){t._restClient._get("users/"+e,{},function(e){s(e)},function(e){n(e)})}}(this);