// Ensure a compatible global for UMD and enable CommonJS exports in Mini Program if (typeof global === "undefined") { var global = (typeof globalThis !== "undefined") ? globalThis : (typeof self !== "undefined" ? self : (typeof window !== "undefined" ? window : {})); } /******************************************************************************* * Copyright (c) 2013, 2016 IBM Corp. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompany this distribution. * * The Eclipse Public License is available at * http://www.eclipse.org/legal/epl-v10.html * and the Eclipse Distribution License is available at * http://www.eclipse.org/org/documents/edl-v10.php. * *******************************************************************************/ (function(m,r){ var out = r(); if (typeof m.Paho === "undefined") m.Paho = {}; m.Paho.MQTT = out; })(global,function(){return function(m){function r(a,b,d){b[d++]=a>>8;b[d++]=a%256;return d}function u(a,b,d,k){k=r(b,d,k);D(a,d,k);return k+b}function p(a){for(var b=0,d=0;d=k&&(d++,b++),b+=3):127=e){var f=a.charCodeAt(++k);if(isNaN(f))throw Error(h(g.MALFORMED_UNICODE,[e,f]));e=(e-55296<<10)+(f-56320)+65536}127>=e?b[d++]=e:(2047>=e?b[d++]=e>>6&31|192:(65535>=e?b[d++]=e>>12&15|224:(b[d++]=e>>18&7|240,b[d++]=e>>12&63|128),b[d++]=e>>6&63|128),b[d++]=e&63|128)}return b}function E(a,b,d){for(var k="",e,f=b;fe)){var n=a[f++]-128;if(0>n)throw Error(h(g.MALFORMED_UTF,[e.toString(16),n.toString(16), ""]));if(224>e)e=64*(e-192)+n;else{var c=a[f++]-128;if(0>c)throw Error(h(g.MALFORMED_UTF,[e.toString(16),n.toString(16),c.toString(16)]));if(240>e)e=4096*(e-224)+64*n+c;else{var l=a[f++]-128;if(0>l)throw Error(h(g.MALFORMED_UTF,[e.toString(16),n.toString(16),c.toString(16),l.toString(16)]));if(248>e)e=262144*(e-240)+4096*n+64*c+l;else throw Error(h(g.MALFORMED_UTF,[e.toString(16),n.toString(16),c.toString(16),l.toString(16)]));}}}65535>10)),e=56320+(e& 1023));k+=String.fromCharCode(e)}return k}var y=function(a,b){for(var d in a)if(a.hasOwnProperty(d))if(b.hasOwnProperty(d)){if(typeof a[d]!==b[d])throw Error(h(g.INVALID_TYPE,[typeof a[d],d]));}else{d="Unknown property, "+d+". Valid properties are:";for(var k in b)b.hasOwnProperty(k)&&(d=d+" "+k);throw Error(d);}},s=function(a,b){return function(){return a.apply(b,arguments)}},g={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\x3d{0} value\x3d{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}."},BUFFER_FULL:{code:18,text:"AMQJS0018E Message buffer is full, maximum buffer size: {0}."}},H={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"},h=function(a,b){var d=a.text;if(b)for(var k,e,f=0;f>7;0h);c=f.length+1;b=new ArrayBuffer(b+c);h=new Uint8Array(b);h[0]=a;h.set(f,1);if(3==this.type)c=u(this.payloadMessage.destinationName,k,h,c);else if(1==this.type){switch(this.mqttVersion){case 3:h.set(A,c);c+=A.length; break;case 4:h.set(B,c),c+=B.length}a=0;this.cleanSession&&(a=2);void 0!==this.willMessage&&(a=a|4|this.willMessage.qos<<3,this.willMessage.retained&&(a|=32));void 0!==this.userName&&(a|=128);void 0!==this.password&&(a|=64);h[c++]=a;c=r(this.keepAliveInterval,h,c)}void 0!==this.messageIdentifier&&(c=r(this.messageIdentifier,h,c));switch(this.type){case 1:c=u(this.clientId,p(this.clientId),h,c);void 0!==this.willMessage&&(c=u(this.willMessage.destinationName,p(this.willMessage.destinationName),h,c), c=r(e.byteLength,h,c),h.set(e,c),c+=e.byteLength);void 0!==this.userName&&(c=u(this.userName,p(this.userName),h,c));void 0!==this.password&&u(this.password,p(this.password),h,c);break;case 3:h.set(g,c);break;case 8:for(f=0;f this.disconnectedBufferSize)throw Error(h(g.BUFFER_FULL,[this.disconnectedBufferSize]));0=e[f]?c+"0"+e[f].toString(16):c+e[f].toString(16);d.payloadMessage.payloadHex=c;d.payloadMessage.qos=b.payloadMessage.qos;d.payloadMessage.destinationName=b.payloadMessage.destinationName;b.payloadMessage.duplicate&&(d.payloadMessage.duplicate=!0);b.payloadMessage.retained&&(d.payloadMessage.retained= !0);0===a.indexOf("Sent:")&&(void 0===b.sequence&&(b.sequence=++this._sequence),d.sequence=b.sequence);break;default:throw Error(h(g.INVALID_STORED_DATA,[key,d]));}try{m.setStorageSync(a+this._localKey+b.messageIdentifier,JSON.stringify(d))}catch(n){}};c.prototype.restore=function(a){var b=m.getStorageSync(a),d=JSON.parse(b),c=new q(d.type,d);switch(d.type){case 3:for(var b=d.payloadMessage.payloadHex,e=new ArrayBuffer(b.length/2),e=new Uint8Array(e),f=0;2<=b.length;){var n=parseInt(b.substring(0, 2),16),b=b.substring(2,b.length);e[f++]=n}b=new v(e);b.qos=d.payloadMessage.qos;b.destinationName=d.payloadMessage.destinationName;d.payloadMessage.duplicate&&(b.duplicate=!0);d.payloadMessage.retained&&(b.retained=!0);c.payloadMessage=b;break;default:throw Error(h(g.INVALID_STORED_DATA,[a,b]));}0===a.indexOf("Sent:"+this._localKey)?(c.payloadMessage.duplicate=!0,this._sentMessages[c.messageIdentifier]=c):0===a.indexOf("Received:"+this._localKey)&&(this._receivedMessages[c.messageIdentifier]=c)}; c.prototype._process_queue=function(){for(var a=null,b=this._msg_queue.reverse();a=b.pop();)this._socket_send(a),this._notify_msg_sent[a]&&(this._notify_msg_sent[a](),delete this._notify_msg_sent[a])};c.prototype._requires_ack=function(a){var b=Object.keys(this._sentMessages).length;if(b>this.maxMessageIdentifier)throw Error("Too many messages:"+b);for(;void 0!==this._sentMessages[this._message_identifier];)this._message_identifier++;a.messageIdentifier=this._message_identifier;this._sentMessages[a.messageIdentifier]= a;3===a.type&&this.store("Sent:",a);this._message_identifier===this.maxMessageIdentifier&&(this._message_identifier=1)};c.prototype._on_socket_open=function(a){a=new q(1,this.connectOptions);a.clientId=this.clientId;this._socket_send(a)};c.prototype._on_socket_message=function(a){this._trace("Client._on_socket_message",a.data);a=this._deframeMessages(a.data);for(var b=0;b>4,t=m&15,f=f+1,w=void 0,C=0,p=1;do{if(f==e.length){c=[null,n];break a}w=e[f++];C+=(w&127)*p;p*=128}while(0!==(w&128));w=f+C;if(w>e.length)c=[null,n];else{var x=new q(l);switch(l){case 2:e[f++]&1&&(x.sessionPresent=!0);x.returnCode=e[f++];break;case 3:var n=t>>1&3,r=256*e[f]+e[f+1],f=f+2,u=E(e,f,r), f=f+r;0this._reconnectInterval&&(this._reconnectInterval*=2),this.connectOptions.uris?(this.hostIndex=0,this._doConnect(this.connectOptions.uris[0])):this._doConnect(this.uri))};c.prototype._disconnected=function(a,b){this._trace("Client._disconnected",a,b);if(void 0!==a&&this._reconnecting)this._reconnectTimeout=new z(this,this._reconnectInterval, this._reconnect);else if(this.sendPinger.cancel(),this.receivePinger.cancel(),this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null),this._msg_queue=[],this._buffered_msg_queue=[],this._notify_msg_sent={},this.connectOptions.uris&&this.hostIndexb)throw Error(h(g.INVALID_TYPE,[typeof b,"port"]));if("string"!==typeof d)throw Error(h(g.INVALID_TYPE,[typeof d,"path"]));e="ws://"+(-1!==a.indexOf(":")&&"["!==a.slice(0,1)&&"]"!==a.slice(-1)?"["+a+"]":a)+":"+b+d}for(var n=f=0;n=m&&n++;f++}if("string"!==typeof k||65535a.mqttVersion)throw Error(h(g.INVALID_ARGUMENT,[a.mqttVersion,"connectOptions.mqttVersion"]));void 0===a.mqttVersion?(a.mqttVersionExplicit=!1,a.mqttVersion=4):a.mqttVersionExplicit=!0;if(void 0!==a.password&&void 0===a.userName)throw Error(h(g.INVALID_ARGUMENT,[a.password,"connectOptions.password"]));if(a.willMessage){if(!(a.willMessage instanceof v))throw Error(h(g.INVALID_TYPE,[a.willMessage,"connectOptions.willMessage"]));a.willMessage.stringPayload=null;if("undefined"===typeof a.willMessage.destinationName)throw Error(h(g.INVALID_TYPE,[typeof a.willMessage.destinationName,"connectOptions.willMessage.destinationName"]));}"undefined"===typeof a.cleanSession&&(a.cleanSession=!0);if(a.hosts){if(!(a.hosts instanceof Array))throw Error(h(g.INVALID_ARGUMENT,[a.hosts,"connectOptions.hosts"]));if(1>a.hosts.length)throw Error(h(g.INVALID_ARGUMENT, [a.hosts,"connectOptions.hosts"]));for(var b=!1,c=0;ca.ports[c])throw Error(h(g.INVALID_TYPE,[typeof a.ports[c],"connectOptions.ports["+c+"]"]));var b=a.hosts[c],f=a.ports[c];e="ws://"+(-1!==b.indexOf(":")?"["+b+"]":b)+":"+f+d;a.uris.push(e)}}}l.connect(a)}; this.subscribe=function(a,b){if("string"!==typeof a)throw Error("Invalid argument:"+a);b=b||{};y(b,{qos:"number",invocationContext:"object",onSuccess:"function",onFailure:"function",timeout:"number"});if(b.timeout&&!b.onFailure)throw Error("subscribeOptions.timeout specified with no onFailure callback.");if("undefined"!==typeof b.qos&&0!==b.qos&&1!==b.qos&&2!==b.qos)throw Error(h(g.INVALID_ARGUMENT,[b.qos,"subscribeOptions.qos"]));l.subscribe(a,b)};this.unsubscribe=function(a,b){if("string"!==typeof a)throw Error("Invalid argument:"+ a);b=b||{};y(b,{invocationContext:"object",onSuccess:"function",onFailure:"function",timeout:"number"});if(b.timeout&&!b.onFailure)throw Error("unsubscribeOptions.timeout specified with no onFailure callback.");l.unsubscribe(a,b)};this.send=function(a,b,c,d){var e;if(0===arguments.length)throw Error("Invalid argument.length");if(1==arguments.length){if(!(a instanceof v)&&"string"!==typeof a)throw Error("Invalid argument:"+typeof a);e=a;if("undefined"===typeof e.destinationName)throw Error(h(g.INVALID_ARGUMENT, [e.destinationName,"Message.destinationName"]));}else e=new v(b),e.destinationName=a,3<=arguments.length&&(e.qos=c),4<=arguments.length&&(e.retained=d);l.send(e)};this.publish=function(a,b,c,d){console.log("Publising message to: ",a);var e;if(0===arguments.length)throw Error("Invalid argument.length");if(1==arguments.length){if(!(a instanceof v)&&"string"!==typeof a)throw Error("Invalid argument:"+typeof a);e=a;if("undefined"===typeof e.destinationName)throw Error(h(g.INVALID_ARGUMENT,[e.destinationName, "Message.destinationName"]));}else e=new v(b),e.destinationName=a,3<=arguments.length&&(e.qos=c),4<=arguments.length&&(e.retained=d);l.send(e)};this.disconnect=function(){l.disconnect()};this.getTraceLog=function(){return l.getTraceLog()};this.startTrace=function(){l.startTrace()};this.stopTrace=function(){l.stopTrace()};this.isConnected=function(){return l.connected}};G.prototype={get host(){return this._getHost()},set host(a){this._setHost(a)},get port(){return this._getPort()},set port(a){this._setPort(a)}, get path(){return this._getPath()},set path(a){this._setPath(a)},get clientId(){return this._getClientId()},set clientId(a){this._setClientId(a)},get onConnected(){return this._getOnConnected()},set onConnected(a){this._setOnConnected(a)},get disconnectedPublishing(){return this._getDisconnectedPublishing()},set disconnectedPublishing(a){this._setDisconnectedPublishing(a)},get disconnectedBufferSize(){return this._getDisconnectedBufferSize()},set disconnectedBufferSize(a){this._setDisconnectedBufferSize(a)}, get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(a){this._setOnConnectionLost(a)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(a){this._setOnMessageDelivered(a)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(a){this._setOnMessageArrived(a)},get trace(){return this._getTrace()},set trace(a){this._setTrace(a)}};var v=function(a){var b;if("string"===typeof a||a instanceof ArrayBuffer||a instanceof Int8Array||a instanceof Uint8Array||a instanceof Int16Array||a instanceof Uint16Array||a instanceof Int32Array||a instanceof Uint32Array||a instanceof Float32Array||a instanceof Float64Array)b=a;else throw h(g.INVALID_ARGUMENT,[a,"newPayload"]);this._getPayloadString=function(){return"string"===typeof b?b:E(b,0,b.length)};this._getPayloadBytes=function(){if("string"===typeof b){var a=new ArrayBuffer(p(b)),a=new Uint8Array(a);D(b,a,0);return a}return b};var c;this._getDestinationName=function(){return c}; this._setDestinationName=function(a){if("string"===typeof a)c=a;else throw Error(h(g.INVALID_ARGUMENT,[a,"newDestinationName"]));};var k=0;this._getQos=function(){return k};this._setQos=function(a){if(0===a||1===a||2===a)k=a;else throw Error("Invalid argument:"+a);};var e=!1;this._getRetained=function(){return e};this._setRetained=function(a){if("boolean"===typeof a)e=a;else throw Error(h(g.INVALID_ARGUMENT,[a,"newRetained"]));};var f=!1;this._getDuplicate=function(){return f};this._setDuplicate= function(a){f=a}};v.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(a){this._setDestinationName(a)},get topic(){return this._getDestinationName()},set topic(a){this._setDestinationName(a)},get qos(){return this._getQos()},set qos(a){this._setQos(a)},get retained(){return this._getRetained()},set retained(a){this._setRetained(a)},get duplicate(){return this._getDuplicate()}, set duplicate(a){this._setDuplicate(a)}};return{Client:G,Message:v}}(wx)}); // ESM only export const __PahoMQTT = (typeof global !== 'undefined' && global.Paho && global.Paho.MQTT) ? global.Paho.MQTT : null; export default __PahoMQTT;