amplify-js: Dependency on paho-mqtt should be removed - package is no longer maintained and contains bugs

Before opening, please confirm:

JavaScript Framework

Not applicable

Amplify APIs

PubSub

Amplify Categories

Not applicable

Environment information

# Put output below this line


  System:
    OS: macOS 11.6
    CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
    Memory: 20.23 GB / 64.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.18.1 - ~/.volta/tools/image/node/14.18.1/bin/node
    Yarn: 2.4.1 - ~/.volta/tools/image/yarn/1.22.17/bin/yarn
    npm: 6.14.15 - ~/.volta/tools/image/node/14.18.1/bin/npm
    Watchman: 2021.11.01.00 - /usr/local/bin/watchman
  Browsers:
    Brave Browser: 91.1.26.74
    Chrome: 95.0.4638.69
    Firefox: 94.0.1
    Safari: 15.0
  npmPackages:
    @babel/core: ^7.15.5 => 7.15.5 (7.15.0, 7.14.3)
    @maxmind/geoip2-node: ^3.2.0 => 3.2.0 
    @nuxt/types: ~2.15.8 => 2.15.8 
    @nuxtjs/axios: ^5.13.6 => 5.13.6 
    @nuxtjs/eslint-config: ^5.0.0 => 5.0.0 
    @nuxtjs/eslint-module: ^3.0.2 => 3.0.2 
    @nuxtjs/sentry: ^5.1.4 => 5.1.4 
    @nuxtjs/vuetify: ^1.12.1 => 1.12.1 
    @vue/cli-plugin-babel: ^4.5.13 => 4.5.13 
    @vue/eslint-config-standard: ^6.1.0 => 6.1.0 
    aliyun-nodejs:  1.0.0 
    aws-alexa-typescript:  1.0.0 
    aws-amplify: ^4.3.1 => 4.3.1 
    aws-nodejs-ecma-script:  1.0.0 
    aws-nodejs-typescript:  1.0.0 
    azure-nodejs:  1.0.0 
    azure-nodejs-typescript:  1.0.0 
    azure-python:  1.0.0 
    babel-eslint: ^10.1.0 => 10.1.0 
    babel-jest: ^27.2.4 => 27.2.4 
    camelcase-keys: ^6.2.2 => 6.2.2 (7.0.0)
    change-case: ^4.1.2 => 4.1.2 
    cloudflare-workers:  1.0.0 
    cloudflare-workers-enterprise:  1.0.0 
    cloudflare-workers-rust:  1.0.0 
    cookie-universal-nuxt: ^2.1.5 => 2.1.5 
    core-js: ^3.18.1 => 3.18.1 (2.6.12, 3.16.1, 3.16.0)
    debug: ^4.3.2 => 4.3.2 (2.6.9, 3.1.0, 3.2.7)
    dev:  1.0.0 
    env-cmd: ^10.1.0 => 10.1.0 
    eslint: ^7.32.0 => 7.32.0 
    eslint-config-prettier: ^7.2.0 => 7.2.0 
    eslint-plugin-nuxt: ^2.0.0 => 2.0.0 
    eslint-plugin-prettier: ^3.4.1 => 3.4.1 
    eslint-plugin-vue: ^7.18.0 => 7.18.0 (7.10.0)
    fn-go:  1.0.0 
    fn-node:  1.0.0 
    google-nodejs:  0.1.0 
    google-nodejs-typescript:  1.0.0 
    google-python:  0.1.0 
    hellofn:  1.0.0 
    husky: ^4.3.8 => 4.3.8 
    jest: ^27.2.4 => 27.2.4 
    knative-docker:  1.0.0 
    konva: ^8.2.1 => 8.2.1 
    kubeless-nodejs:  1.0.0 
    kubeless-python:  1.0.0 
    lint-staged: ^10.5.4 => 10.5.4 
    lodash.debounce: ^4.0.8 => 4.0.8 
    nuxt: ^2.15.8 => 2.15.8 
    nuxt-start: ^2.15.8 => 2.15.8 
    openwhisk-java:  1.0.0 
    openwhisk-nodejs:  1.0.0 
    openwhisk-php:  1.0.0 
    openwhisk-python:  1.0.0 
    openwhisk-ruby:  1.0.0 
    openwhisk-swift:  1.0.0 
    plyr: ^3.6.8 => 3.6.8 
    prettier: ^2.4.1 => 2.4.1 (1.19.1)
    serverless: ^2.59.0 => 2.59.0 
    serverless-apigw-binary: ^0.4.4 => 0.4.4 
    serverless-domain-manager: ^5.1.5 => 5.1.5 
    serverless-google-hello-world:  0.1.0 
    serverless-nuxt: ^1.1.2 => 1.1.2 
    serverless-nuxt-plugin: ^1.5.0 => 1.5.0 
    serverless-openwhisk-hello-world:  0.1.0 
    serverless-plugin:  1.0.0 
    sls-csharp:  1.0.0 
    spotionst-java8:  1.0.0 
    spotionst-nodejs:  1.0.0 
    spotionst-python:  1.0.0 
    spotionst-ruby:  1.0.0 
    tencent-golang:  1.0.0 
    tencent-nodejs:  1.0.0 
    tencent-php:  1.0.0 
    tencent-python:  1.0.0 
    tinycolor2: ^1.4.2 => 1.4.2 
    twilio-nodejs-runtime-example:  1.0.0 
    validator: ^13.6.0 => 13.6.0 
    vue-linkify: ^1.0.1 => 1.0.1 
    vuetify: ^2.5.9 => 2.5.9 (2.5.3)
    vuetify-loader: ^1.7.3 => 1.7.3 (1.7.2)
    vuex: ^3.6.2 => 3.6.2 
    waveform-data: ^4.1.1 => 4.1.1 
  npmGlobalPackages:
    npm: 6.14.15

Describe the bug

AWS Amplify should definitely consider replacing paho-mqtt with something else. It’s a package that’s no longer maintained, and has issues which are causing Amplify to break.

While there are workarounds like using patch-package to monkey patch it, this isn’t ideal as many people don’t know this is even possible (I didn’t know until today!).

Expected behavior

N/A

Reproduction steps

N/A

Code Snippet

No response

Log output

No response

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

Hello @ffxsam,

The change that includes the paho-mqtt patch in Amplify was released today. If you upgrade to aws-amplify@5.0.10 or later, your application should support PubSub for users who have cookies disabled.

Hi @ffxsam - We’ve had a couple of investigations on this that have not been fully completed, our issue has been identifying a dependency that we can use that can provide us with coverage to both Web and React Native. There is still some ground work for us to do - and we’ll respond back with updates when we have them.

Hey @abdallahshaban557! I could be way off base, but this seems like a somewhat critical issue? (is “somewhat” critical a thing? 😆)

@yaquawa I sure did. The solution was to use Yarn’s patch feature (make sure you’re using Yarn 3.x). But I can save you most of the work.

In case you’re using the old Yarn 1.x, the quickest way to switch to the latest version:

$ cd myproject
$ yarn set version berry
$ yarn config set nodeLinker node-modules

and add this to your .gitignore:

# Yarn 2
.yarn/*
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*

Once that’s all set up, copy this file into .yarn/patches:

paho-mqtt-npm-1.1.0-c2bf8169e8
diff --git a/paho-mqtt-min.js b/paho-mqtt-min.js
index c24e9b7ba683ac70fefccac54c4bab7bb4719ccf..9b9753b9b39ea454ea1da509805a548f1c329951 100644
--- a/paho-mqtt-min.js
+++ b/paho-mqtt-min.js
@@ -1,75 +1 @@
-/*******************************************************************************
- * 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(t,q){"object"===typeof exports&&"object"===typeof module?module.exports=q():"function"===typeof define&&define.amd?define(q):"object"===typeof exports?exports=q():t.Paho=q()})(this,function(){return function(t){function q(a,b,c){b[c++]=a>>8;b[c++]=a%256;return c}function r(a,b,c,k){k=q(b,c,k);E(a,c,k);return k+b}function n(a){for(var b=0,c=0;c<a.length;c++){var k=a.charCodeAt(c);2047<k?(55296<=k&&56319>=k&&(c++,b++),b+=3):127<k?b+=2:b++}return b}function E(a,b,c){for(var k=0;k<a.length;k++){var e=
-    a.charCodeAt(k);if(55296<=e&&56319>=e){var g=a.charCodeAt(++k);if(isNaN(g))throw Error(f(h.MALFORMED_UNICODE,[e,g]));e=(e-55296<<10)+(g-56320)+65536}127>=e?b[c++]=e:(2047>=e?b[c++]=e>>6&31|192:(65535>=e?b[c++]=e>>12&15|224:(b[c++]=e>>18&7|240,b[c++]=e>>12&63|128),b[c++]=e>>6&63|128),b[c++]=e&63|128)}return b}function F(a,b,c){for(var k="",e,g=b;g<b+c;){e=a[g++];if(!(128>e)){var m=a[g++]-128;if(0>m)throw Error(f(h.MALFORMED_UTF,[e.toString(16),m.toString(16),""]));if(224>e)e=64*(e-192)+m;else{var d=
-    a[g++]-128;if(0>d)throw Error(f(h.MALFORMED_UTF,[e.toString(16),m.toString(16),d.toString(16)]));if(240>e)e=4096*(e-224)+64*m+d;else{var l=a[g++]-128;if(0>l)throw Error(f(h.MALFORMED_UTF,[e.toString(16),m.toString(16),d.toString(16),l.toString(16)]));if(248>e)e=262144*(e-240)+4096*m+64*d+l;else throw Error(f(h.MALFORMED_UTF,[e.toString(16),m.toString(16),d.toString(16),l.toString(16)]));}}}65535<e&&(e-=65536,k+=String.fromCharCode(55296+(e>>10)),e=56320+(e&1023));k+=String.fromCharCode(e)}return k}
-    var s=t.localStorage||function(){var a={};return{setItem:function(b,c){a[b]=c},getItem:function(b){return a[b]},removeItem:function(b){delete a[b]}}}(),A=function(a,b){for(var c in a)if(a.hasOwnProperty(c))if(b.hasOwnProperty(c)){if(typeof a[c]!==b[c])throw Error(f(h.INVALID_TYPE,[typeof a[c],c]));}else{c="Unknown property, "+c+". Valid properties are:";for(var k in b)b.hasOwnProperty(k)&&(c=c+" "+k);throw Error(c);}},u=function(a,b){return function(){return a.apply(b,arguments)}},h={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"},
-    f=function(a,b){var c=a.text;if(b)for(var k,e,g=0;g<b.length;g++)if(k="{"+g+"}",e=c.indexOf(k),0<e)var h=c.substring(0,e),c=c.substring(e+k.length),c=h+b[g]+c;return c},B=[0,6,77,81,73,115,100,112,3],C=[0,4,77,81,84,84,4],p=function(a,b){this.type=a;for(var c in b)b.hasOwnProperty(c)&&(this[c]=b[c])};p.prototype.encode=function(){var a=(this.type&15)<<4,b=0,c=[],k=0,e;void 0!==this.messageIdentifier&&(b+=2);switch(this.type){case 1:switch(this.mqttVersion){case 3:b+=B.length+3;break;case 4:b+=C.length+
-    3}b+=n(this.clientId)+2;void 0!==this.willMessage&&(b+=n(this.willMessage.destinationName)+2,e=this.willMessage.payloadBytes,e instanceof Uint8Array||(e=new Uint8Array(h)),b+=e.byteLength+2);void 0!==this.userName&&(b+=n(this.userName)+2);void 0!==this.password&&(b+=n(this.password)+2);break;case 8:for(var a=a|2,g=0;g<this.topics.length;g++)c[g]=n(this.topics[g]),b+=c[g]+2;b+=this.requestedQos.length;break;case 10:a|=2;for(g=0;g<this.topics.length;g++)c[g]=n(this.topics[g]),b+=c[g]+2;break;case 6:a|=
-    2;break;case 3:this.payloadMessage.duplicate&&(a|=8);a=a|=this.payloadMessage.qos<<1;this.payloadMessage.retained&&(a|=1);var k=n(this.payloadMessage.destinationName),h=this.payloadMessage.payloadBytes,b=b+(k+2)+h.byteLength;h instanceof ArrayBuffer?h=new Uint8Array(h):h instanceof Uint8Array||(h=new Uint8Array(h.buffer))}var f=b,g=Array(1),d=0;do{var z=f%128,f=f>>7;0<f&&(z|=128);g[d++]=z}while(0<f&&4>d);f=g.length+1;b=new ArrayBuffer(b+f);d=new Uint8Array(b);d[0]=a;d.set(g,1);if(3==this.type)f=r(this.payloadMessage.destinationName,
-    k,d,f);else if(1==this.type){switch(this.mqttVersion){case 3:d.set(B,f);f+=B.length;break;case 4:d.set(C,f),f+=C.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);d[f++]=a;f=q(this.keepAliveInterval,d,f)}void 0!==this.messageIdentifier&&(f=q(this.messageIdentifier,d,f));switch(this.type){case 1:f=r(this.clientId,n(this.clientId),d,f);void 0!==this.willMessage&&
-    (f=r(this.willMessage.destinationName,n(this.willMessage.destinationName),d,f),f=q(e.byteLength,d,f),d.set(e,f),f+=e.byteLength);void 0!==this.userName&&(f=r(this.userName,n(this.userName),d,f));void 0!==this.password&&r(this.password,n(this.password),d,f);break;case 3:d.set(h,f);break;case 8:for(g=0;g<this.topics.length;g++)f=r(this.topics[g],c[g],d,f),d[f++]=this.requestedQos[g];break;case 10:for(g=0;g<this.topics.length;g++)f=r(this.topics[g],c[g],d,f)}return b};var G=function(a,b){this._client=
-    a;this._keepAliveInterval=1E3*b;this.isReset=!1;var c=(new p(12)).encode(),k=function(a){return function(){return e.apply(a)}},e=function(){this.isReset?(this.isReset=!1,this._client._trace("Pinger.doPing","send PINGREQ"),this._client.socket.send(c),this.timeout=setTimeout(k(this),this._keepAliveInterval)):(this._client._trace("Pinger.doPing","Timed out"),this._client._disconnected(h.PING_TIMEOUT.code,f(h.PING_TIMEOUT)))};this.reset=function(){this.isReset=!0;clearTimeout(this.timeout);0<this._keepAliveInterval&&
-    (this.timeout=setTimeout(k(this),this._keepAliveInterval))};this.cancel=function(){clearTimeout(this.timeout)}},v=function(a,b,c,f){b||(b=30);this.timeout=setTimeout(function(a,b,c){return function(){return a.apply(b,c)}}(c,a,f),1E3*b);this.cancel=function(){clearTimeout(this.timeout)}},d=function(a,b,c,d,e){if(!("WebSocket"in t&&null!==t.WebSocket))throw Error(f(h.UNSUPPORTED,["WebSocket"]));if(!("ArrayBuffer"in t&&null!==t.ArrayBuffer))throw Error(f(h.UNSUPPORTED,["ArrayBuffer"]));this._trace("Paho.Client",
-    a,b,c,d,e);this.host=b;this.port=c;this.path=d;this.uri=a;this.clientId=e;this._wsuri=null;this._localKey=b+":"+c+("/mqtt"!=d?":"+d:"")+":"+e+":";this._msg_queue=[];this._buffered_msg_queue=[];this._sentMessages={};this._receivedMessages={};this._notify_msg_sent={};this._message_identifier=1;this._sequence=0;for(var g in s)0!==g.indexOf("Sent:"+this._localKey)&&0!==g.indexOf("Received:"+this._localKey)||this.restore(g)};d.prototype.host=null;d.prototype.port=null;d.prototype.path=null;d.prototype.uri=
-    null;d.prototype.clientId=null;d.prototype.socket=null;d.prototype.connected=!1;d.prototype.maxMessageIdentifier=65536;d.prototype.connectOptions=null;d.prototype.hostIndex=null;d.prototype.onConnected=null;d.prototype.onConnectionLost=null;d.prototype.onMessageDelivered=null;d.prototype.onMessageArrived=null;d.prototype.traceFunction=null;d.prototype._msg_queue=null;d.prototype._buffered_msg_queue=null;d.prototype._connectTimeout=null;d.prototype.sendPinger=null;d.prototype.receivePinger=null;d.prototype._reconnectInterval=
-    1;d.prototype._reconnecting=!1;d.prototype._reconnectTimeout=null;d.prototype.disconnectedPublishing=!1;d.prototype.disconnectedBufferSize=5E3;d.prototype.receiveBuffer=null;d.prototype._traceBuffer=null;d.prototype._MAX_TRACE_ENTRIES=100;d.prototype.connect=function(a){var b=this._traceMask(a,"password");this._trace("Client.connect",b,this.socket,this.connected);if(this.connected)throw Error(f(h.INVALID_STATE,["already connected"]));if(this.socket)throw Error(f(h.INVALID_STATE,["already connected"]));
-    this._reconnecting&&(this._reconnectTimeout.cancel(),this._reconnectTimeout=null,this._reconnecting=!1);this.connectOptions=a;this._reconnectInterval=1;this._reconnecting=!1;a.uris?(this.hostIndex=0,this._doConnect(a.uris[0])):this._doConnect(this.uri)};d.prototype.subscribe=function(a,b){this._trace("Client.subscribe",a,b);if(!this.connected)throw Error(f(h.INVALID_STATE,["not connected"]));var c=new p(8);c.topics=a.constructor===Array?a:[a];void 0===b.qos&&(b.qos=0);c.requestedQos=[];for(var d=
-    0;d<c.topics.length;d++)c.requestedQos[d]=b.qos;b.onSuccess&&(c.onSuccess=function(a){b.onSuccess({invocationContext:b.invocationContext,grantedQos:a})});b.onFailure&&(c.onFailure=function(a){b.onFailure({invocationContext:b.invocationContext,errorCode:a,errorMessage:f(a)})});b.timeout&&(c.timeOut=new v(this,b.timeout,b.onFailure,[{invocationContext:b.invocationContext,errorCode:h.SUBSCRIBE_TIMEOUT.code,errorMessage:f(h.SUBSCRIBE_TIMEOUT)}]));this._requires_ack(c);this._schedule_message(c)};d.prototype.unsubscribe=
-    function(a,b){this._trace("Client.unsubscribe",a,b);if(!this.connected)throw Error(f(h.INVALID_STATE,["not connected"]));var c=new p(10);c.topics=a.constructor===Array?a:[a];b.onSuccess&&(c.callback=function(){b.onSuccess({invocationContext:b.invocationContext})});b.timeout&&(c.timeOut=new v(this,b.timeout,b.onFailure,[{invocationContext:b.invocationContext,errorCode:h.UNSUBSCRIBE_TIMEOUT.code,errorMessage:f(h.UNSUBSCRIBE_TIMEOUT)}]));this._requires_ack(c);this._schedule_message(c)};d.prototype.send=
-    function(a){this._trace("Client.send",a);var b=new p(3);b.payloadMessage=a;if(this.connected)0<a.qos?this._requires_ack(b):this.onMessageDelivered&&(this._notify_msg_sent[b]=this.onMessageDelivered(b.payloadMessage)),this._schedule_message(b);else if(this._reconnecting&&this.disconnectedPublishing){if(Object.keys(this._sentMessages).length+this._buffered_msg_queue.length>this.disconnectedBufferSize)throw Error(f(h.BUFFER_FULL,[this.disconnectedBufferSize]));0<a.qos?this._requires_ack(b):(b.sequence=
-    ++this._sequence,this._buffered_msg_queue.unshift(b))}else throw Error(f(h.INVALID_STATE,["not connected"]));};d.prototype.disconnect=function(){this._trace("Client.disconnect");this._reconnecting&&(this._reconnectTimeout.cancel(),this._reconnectTimeout=null,this._reconnecting=!1);if(!this.socket)throw Error(f(h.INVALID_STATE,["not connecting or connected"]));var a=new p(14);this._notify_msg_sent[a]=u(this._disconnected,this);this._schedule_message(a)};d.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 a in this._sentMessages)this._trace("_sentMessages ",a,this._sentMessages[a]);for(a in this._receivedMessages)this._trace("_receivedMessages ",a,this._receivedMessages[a]);return this._traceBuffer}};d.prototype.startTrace=function(){null===this._traceBuffer&&(this._traceBuffer=[]);this._trace("Client.startTrace",new Date,"1.1.0-2018-11-22T11:35:36Z")};d.prototype.stopTrace=
-    function(){delete this._traceBuffer};d.prototype._doConnect=function(a){this.connectOptions.useSSL&&(a=a.split(":"),a[0]="wss",a=a.join(":"));this._wsuri=a;this.connected=!1;this.socket=4>this.connectOptions.mqttVersion?new WebSocket(a,["mqttv3.1"]):new WebSocket(a,["mqtt"]);this.socket.binaryType="arraybuffer";this.socket.onopen=u(this._on_socket_open,this);this.socket.onmessage=u(this._on_socket_message,this);this.socket.onerror=u(this._on_socket_error,this);this.socket.onclose=u(this._on_socket_close,
-    this);this.sendPinger=new G(this,this.connectOptions.keepAliveInterval);this.receivePinger=new G(this,this.connectOptions.keepAliveInterval);this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null);this._connectTimeout=new v(this,this.connectOptions.timeout,this._disconnected,[h.CONNECT_TIMEOUT.code,f(h.CONNECT_TIMEOUT)])};d.prototype._schedule_message=function(a){this._msg_queue.unshift(a);this.connected&&this._process_queue()};d.prototype.store=function(a,b){var c={type:b.type,
-    messageIdentifier:b.messageIdentifier,version:1};switch(b.type){case 3:b.pubRecReceived&&(c.pubRecReceived=!0);c.payloadMessage={};for(var d="",e=b.payloadMessage.payloadBytes,g=0;g<e.length;g++)d=15>=e[g]?d+"0"+e[g].toString(16):d+e[g].toString(16);c.payloadMessage.payloadHex=d;c.payloadMessage.qos=b.payloadMessage.qos;c.payloadMessage.destinationName=b.payloadMessage.destinationName;b.payloadMessage.duplicate&&(c.payloadMessage.duplicate=!0);b.payloadMessage.retained&&(c.payloadMessage.retained=
-    !0);0===a.indexOf("Sent:")&&(void 0===b.sequence&&(b.sequence=++this._sequence),c.sequence=b.sequence);break;default:throw Error(f(h.INVALID_STORED_DATA,[a+this._localKey+b.messageIdentifier,c]));}s.setItem(a+this._localKey+b.messageIdentifier,JSON.stringify(c))};d.prototype.restore=function(a){var b=s.getItem(a),c=JSON.parse(b),d=new p(c.type,c);switch(c.type){case 3:for(var b=c.payloadMessage.payloadHex,e=new ArrayBuffer(b.length/2),e=new Uint8Array(e),g=0;2<=b.length;){var m=parseInt(b.substring(0,
-    2),16),b=b.substring(2,b.length);e[g++]=m}b=new w(e);b.qos=c.payloadMessage.qos;b.destinationName=c.payloadMessage.destinationName;c.payloadMessage.duplicate&&(b.duplicate=!0);c.payloadMessage.retained&&(b.retained=!0);d.payloadMessage=b;break;default:throw Error(f(h.INVALID_STORED_DATA,[a,b]));}0===a.indexOf("Sent:"+this._localKey)?(d.payloadMessage.duplicate=!0,this._sentMessages[d.messageIdentifier]=d):0===a.indexOf("Received:"+this._localKey)&&(this._receivedMessages[d.messageIdentifier]=d)};
-    d.prototype._process_queue=function(){for(var a=null;a=this._msg_queue.pop();)this._socket_send(a),this._notify_msg_sent[a]&&(this._notify_msg_sent[a](),delete this._notify_msg_sent[a])};d.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)};d.prototype._on_socket_open=function(){var a=new p(1,this.connectOptions);a.clientId=this.clientId;this._socket_send(a)};d.prototype._on_socket_message=function(a){this._trace("Client._on_socket_message",a.data);a=this._deframeMessages(a.data);for(var b=0;b<a.length;b+=1)this._handleMessage(a[b])};d.prototype._deframeMessages=function(a){a=new Uint8Array(a);var b=[];if(this.receiveBuffer){var c=
-    new Uint8Array(this.receiveBuffer.length+a.length);c.set(this.receiveBuffer);c.set(a,this.receiveBuffer.length);a=c;delete this.receiveBuffer}try{for(c=0;c<a.length;){var d;a:{var e=a,g=c,m=g,n=e[g],l=n>>4,z=n&15,g=g+1,x=void 0,D=0,q=1;do{if(g==e.length){d=[null,m];break a}x=e[g++];D+=(x&127)*q;q*=128}while(0!==(x&128));x=g+D;if(x>e.length)d=[null,m];else{var y=new p(l);switch(l){case 2:e[g++]&1&&(y.sessionPresent=!0);y.returnCode=e[g++];break;case 3:var m=z>>1&3,s=256*e[g]+e[g+1],g=g+2,t=F(e,g,s),
-    g=g+s;0<m&&(y.messageIdentifier=256*e[g]+e[g+1],g+=2);var r=new w(e.subarray(g,x));1==(z&1)&&(r.retained=!0);8==(z&8)&&(r.duplicate=!0);r.qos=m;r.destinationName=t;y.payloadMessage=r;break;case 4:case 5:case 6:case 7:case 11:y.messageIdentifier=256*e[g]+e[g+1];break;case 9:y.messageIdentifier=256*e[g]+e[g+1],g+=2,y.returnCode=e.subarray(g,x)}d=[y,x]}}var u=d[0],c=d[1];if(null!==u)b.push(u);else break}c<a.length&&(this.receiveBuffer=a.subarray(c))}catch(v){d="undefined"==v.hasOwnProperty("stack")?
-    v.stack.toString():"No Error Stack Available";this._disconnected(h.INTERNAL_ERROR.code,f(h.INTERNAL_ERROR,[v.message,d]));return}return b};d.prototype._handleMessage=function(a){this._trace("Client._handleMessage",a);try{switch(a.type){case 2:this._connectTimeout.cancel();this._reconnectTimeout&&this._reconnectTimeout.cancel();if(this.connectOptions.cleanSession){for(var b in this._sentMessages){var c=this._sentMessages[b];s.removeItem("Sent:"+this._localKey+c.messageIdentifier)}this._sentMessages=
-    {};for(b in this._receivedMessages){var d=this._receivedMessages[b];s.removeItem("Received:"+this._localKey+d.messageIdentifier)}this._receivedMessages={}}if(0===a.returnCode)this.connected=!0,this.connectOptions.uris&&(this.hostIndex=this.connectOptions.uris.length);else{this._disconnected(h.CONNACK_RETURNCODE.code,f(h.CONNACK_RETURNCODE,[a.returnCode,H[a.returnCode]]));break}a=[];for(var e in this._sentMessages)this._sentMessages.hasOwnProperty(e)&&a.push(this._sentMessages[e]);if(0<this._buffered_msg_queue.length)for(e=
-    null;e=this._buffered_msg_queue.pop();)a.push(e),this.onMessageDelivered&&(this._notify_msg_sent[e]=this.onMessageDelivered(e.payloadMessage));a=a.sort(function(a,b){return a.sequence-b.sequence});e=0;for(var g=a.length;e<g;e++)if(c=a[e],3==c.type&&c.pubRecReceived){var m=new p(6,{messageIdentifier:c.messageIdentifier});this._schedule_message(m)}else this._schedule_message(c);if(this.connectOptions.onSuccess)this.connectOptions.onSuccess({invocationContext:this.connectOptions.invocationContext});
-    c=!1;this._reconnecting&&(c=!0,this._reconnectInterval=1,this._reconnecting=!1);this._connected(c,this._wsuri);this._process_queue();break;case 3:this._receivePublish(a);break;case 4:if(c=this._sentMessages[a.messageIdentifier])if(delete this._sentMessages[a.messageIdentifier],s.removeItem("Sent:"+this._localKey+a.messageIdentifier),this.onMessageDelivered)this.onMessageDelivered(c.payloadMessage);break;case 5:if(c=this._sentMessages[a.messageIdentifier])c.pubRecReceived=!0,m=new p(6,{messageIdentifier:a.messageIdentifier}),
-    this.store("Sent:",c),this._schedule_message(m);break;case 6:d=this._receivedMessages[a.messageIdentifier];s.removeItem("Received:"+this._localKey+a.messageIdentifier);d&&(this._receiveMessage(d),delete this._receivedMessages[a.messageIdentifier]);var n=new p(7,{messageIdentifier:a.messageIdentifier});this._schedule_message(n);break;case 7:c=this._sentMessages[a.messageIdentifier];delete this._sentMessages[a.messageIdentifier];s.removeItem("Sent:"+this._localKey+a.messageIdentifier);if(this.onMessageDelivered)this.onMessageDelivered(c.payloadMessage);
-    break;case 9:if(c=this._sentMessages[a.messageIdentifier]){c.timeOut&&c.timeOut.cancel();if(128===a.returnCode[0]){if(c.onFailure)c.onFailure(a.returnCode)}else if(c.onSuccess)c.onSuccess(a.returnCode);delete this._sentMessages[a.messageIdentifier]}break;case 11:if(c=this._sentMessages[a.messageIdentifier])c.timeOut&&c.timeOut.cancel(),c.callback&&c.callback(),delete this._sentMessages[a.messageIdentifier];break;case 13:this.sendPinger.reset();break;case 14:this._disconnected(h.INVALID_MQTT_MESSAGE_TYPE.code,
-    f(h.INVALID_MQTT_MESSAGE_TYPE,[a.type]));break;default:this._disconnected(h.INVALID_MQTT_MESSAGE_TYPE.code,f(h.INVALID_MQTT_MESSAGE_TYPE,[a.type]))}}catch(l){c="undefined"==l.hasOwnProperty("stack")?l.stack.toString():"No Error Stack Available",this._disconnected(h.INTERNAL_ERROR.code,f(h.INTERNAL_ERROR,[l.message,c]))}};d.prototype._on_socket_error=function(a){this._reconnecting||this._disconnected(h.SOCKET_ERROR.code,f(h.SOCKET_ERROR,[a.data]))};d.prototype._on_socket_close=function(){this._reconnecting||
-    this._disconnected(h.SOCKET_CLOSE.code,f(h.SOCKET_CLOSE))};d.prototype._socket_send=function(a){if(1==a.type){var b=this._traceMask(a,"password");this._trace("Client._socket_send",b)}else this._trace("Client._socket_send",a);this.socket.send(a.encode());this.sendPinger.reset()};d.prototype._receivePublish=function(a){switch(a.payloadMessage.qos){case "undefined":case 0:this._receiveMessage(a);break;case 1:var b=new p(4,{messageIdentifier:a.messageIdentifier});this._schedule_message(b);this._receiveMessage(a);
-    break;case 2:this._receivedMessages[a.messageIdentifier]=a;this.store("Received:",a);a=new p(5,{messageIdentifier:a.messageIdentifier});this._schedule_message(a);break;default:throw Error("Invaild qos\x3d"+a.payloadMessage.qos);}};d.prototype._receiveMessage=function(a){if(this.onMessageArrived)this.onMessageArrived(a.payloadMessage)};d.prototype._connected=function(a,b){if(this.onConnected)this.onConnected(a,b)};d.prototype._reconnect=function(){this._trace("Client._reconnect");this.connected||(this._reconnecting=
-    !0,this.sendPinger.cancel(),this.receivePinger.cancel(),128>this._reconnectInterval&&(this._reconnectInterval*=2),this.connectOptions.uris?(this.hostIndex=0,this._doConnect(this.connectOptions.uris[0])):this._doConnect(this.uri))};d.prototype._disconnected=function(a,b){this._trace("Client._disconnected",a,b);if(void 0!==a&&this._reconnecting)this._reconnectTimeout=new v(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.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]);else if(void 0===a&&(a=h.OK.code,b=f(h.OK)),
-    this.connected){this.connected=!1;if(this.onConnectionLost)this.onConnectionLost({errorCode:a,errorMessage:b,reconnect:this.connectOptions.reconnect,uri:this._wsuri});a!==h.OK.code&&this.connectOptions.reconnect&&(this._reconnectInterval=1,this._reconnect())}else if(4===this.connectOptions.mqttVersion&&!1===this.connectOptions.mqttVersionExplicit)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);else if(this.connectOptions.onFailure)this.connectOptions.onFailure({invocationContext:this.connectOptions.invocationContext,errorCode:a,errorMessage:b})};d.prototype._trace=function(){if(this.traceFunction){var a=Array.prototype.slice.call(arguments),b;for(b in a)"undefined"!==typeof a[b]&&a.splice(b,1,JSON.stringify(a[b]));b=a.join("");this.traceFunction({severity:"Debug",message:b})}if(null!==this._traceBuffer)for(b=0,a=arguments.length;b<a;b++)this._traceBuffer.length==
-    this._MAX_TRACE_ENTRIES&&this._traceBuffer.shift(),0===b?this._traceBuffer.push(arguments[b]):"undefined"===typeof arguments[b]?this._traceBuffer.push(arguments[b]):this._traceBuffer.push("  "+JSON.stringify(arguments[b]))};d.prototype._traceMask=function(a,b){var c={},d;for(d in a)a.hasOwnProperty(d)&&(c[d]=d==b?"******":a[d]);return c};var w=function(a){var b;if("string"===typeof a||a instanceof ArrayBuffer||ArrayBuffer.isView(a)&&!(a instanceof DataView))b=a;else throw f(h.INVALID_ARGUMENT,[a,
-    "newPayload"]);var c,d=0,e=!1,g=!1;Object.defineProperties(this,{payloadString:{enumerable:!0,get:function(){return"string"===typeof b?b:F(b,0,b.length)}},payloadBytes:{enumerable:!0,get:function(){if("string"===typeof b){var a=new ArrayBuffer(n(b)),a=new Uint8Array(a);E(b,a,0);return a}return b}},destinationName:{enumerable:!0,get:function(){return c},set:function(a){if("string"===typeof a)c=a;else throw Error(f(h.INVALID_ARGUMENT,[a,"newDestinationName"]));}},qos:{enumerable:!0,get:function(){return d},
-    set:function(a){if(0===a||1===a||2===a)d=a;else throw Error("Invalid argument:"+a);}},retained:{enumerable:!0,get:function(){return e},set:function(a){if("boolean"===typeof a)e=a;else throw Error(f(h.INVALID_ARGUMENT,[a,"newRetained"]));}},topic:{enumerable:!0,get:function(){return c},set:function(a){c=a}},duplicate:{enumerable:!0,get:function(){return g},set:function(a){g=a}}})};return{Client:function(a,b,c,k){var e;if("string"!==typeof a)throw Error(f(h.INVALID_TYPE,[typeof a,"host"]));if(2==arguments.length){k=
-    b;e=a;var g=e.match(/^(wss?):\/\/((\[(.+)\])|([^\/]+?))(:(\d+))?(\/.*)$/);if(g)a=g[4]||g[2],b=parseInt(g[7]),c=g[8];else throw Error(f(h.INVALID_ARGUMENT,[a,"host"]));}else{3==arguments.length&&(k=c,c="/mqtt");if("number"!==typeof b||0>b)throw Error(f(h.INVALID_TYPE,[typeof b,"port"]));if("string"!==typeof c)throw Error(f(h.INVALID_TYPE,[typeof c,"path"]));e="ws://"+(-1!==a.indexOf(":")&&"["!==a.slice(0,1)&&"]"!==a.slice(-1)?"["+a+"]":a)+":"+b+c}for(var m=g=0;m<k.length;m++){var n=k.charCodeAt(m);
-    55296<=n&&56319>=n&&m++;g++}if("string"!==typeof k||65535<g)throw Error(f(h.INVALID_ARGUMENT,[k,"clientId"]));var l=new d(e,a,b,c,k);Object.defineProperties(this,{host:{get:function(){return a},set:function(){throw Error(f(h.UNSUPPORTED_OPERATION));}},port:{get:function(){return b},set:function(){throw Error(f(h.UNSUPPORTED_OPERATION));}},path:{get:function(){return c},set:function(){throw Error(f(h.UNSUPPORTED_OPERATION));}},uri:{get:function(){return e},set:function(){throw Error(f(h.UNSUPPORTED_OPERATION));
-    }},clientId:{get:function(){return l.clientId},set:function(){throw Error(f(h.UNSUPPORTED_OPERATION));}},onConnected:{get:function(){return l.onConnected},set:function(a){if("function"===typeof a)l.onConnected=a;else throw Error(f(h.INVALID_TYPE,[typeof a,"onConnected"]));}},disconnectedPublishing:{get:function(){return l.disconnectedPublishing},set:function(a){l.disconnectedPublishing=a}},disconnectedBufferSize:{get:function(){return l.disconnectedBufferSize},set:function(a){l.disconnectedBufferSize=
-    a}},onConnectionLost:{get:function(){return l.onConnectionLost},set:function(a){if("function"===typeof a)l.onConnectionLost=a;else throw Error(f(h.INVALID_TYPE,[typeof a,"onConnectionLost"]));}},onMessageDelivered:{get:function(){return l.onMessageDelivered},set:function(a){if("function"===typeof a)l.onMessageDelivered=a;else throw Error(f(h.INVALID_TYPE,[typeof a,"onMessageDelivered"]));}},onMessageArrived:{get:function(){return l.onMessageArrived},set:function(a){if("function"===typeof a)l.onMessageArrived=
-    a;else throw Error(f(h.INVALID_TYPE,[typeof a,"onMessageArrived"]));}},trace:{get:function(){return l.traceFunction},set:function(a){if("function"===typeof a)l.traceFunction=a;else throw Error(f(h.INVALID_TYPE,[typeof a,"onTrace"]));}}});this.connect=function(a){a=a||{};A(a,{timeout:"number",userName:"string",password:"string",willMessage:"object",keepAliveInterval:"number",cleanSession:"boolean",useSSL:"boolean",invocationContext:"object",onSuccess:"function",onFailure:"function",hosts:"object",
-    ports:"object",reconnect:"boolean",mqttVersion:"number",mqttVersionExplicit:"boolean",uris:"object"});void 0===a.keepAliveInterval&&(a.keepAliveInterval=60);if(4<a.mqttVersion||3>a.mqttVersion)throw Error(f(h.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(f(h.INVALID_ARGUMENT,[a.password,"connectOptions.password"]));if(a.willMessage){if(!(a.willMessage instanceof
-    w))throw Error(f(h.INVALID_TYPE,[a.willMessage,"connectOptions.willMessage"]));a.willMessage.stringPayload=null;if("undefined"===typeof a.willMessage.destinationName)throw Error(f(h.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(f(h.INVALID_ARGUMENT,[a.hosts,"connectOptions.hosts"]));if(1>a.hosts.length)throw Error(f(h.INVALID_ARGUMENT,
-    [a.hosts,"connectOptions.hosts"]));for(var b=!1,d=0;d<a.hosts.length;d++){if("string"!==typeof a.hosts[d])throw Error(f(h.INVALID_TYPE,[typeof a.hosts[d],"connectOptions.hosts["+d+"]"]));if(/^(wss?):\/\/((\[(.+)\])|([^\/]+?))(:(\d+))?(\/.*)$/.test(a.hosts[d]))if(0===d)b=!0;else{if(!b)throw Error(f(h.INVALID_ARGUMENT,[a.hosts[d],"connectOptions.hosts["+d+"]"]));}else if(b)throw Error(f(h.INVALID_ARGUMENT,[a.hosts[d],"connectOptions.hosts["+d+"]"]));}if(b)a.uris=a.hosts;else{if(!a.ports)throw Error(f(h.INVALID_ARGUMENT,
-    [a.ports,"connectOptions.ports"]));if(!(a.ports instanceof Array))throw Error(f(h.INVALID_ARGUMENT,[a.ports,"connectOptions.ports"]));if(a.hosts.length!==a.ports.length)throw Error(f(h.INVALID_ARGUMENT,[a.ports,"connectOptions.ports"]));a.uris=[];for(d=0;d<a.hosts.length;d++){if("number"!==typeof a.ports[d]||0>a.ports[d])throw Error(f(h.INVALID_TYPE,[typeof a.ports[d],"connectOptions.ports["+d+"]"]));var b=a.hosts[d],g=a.ports[d];e="ws://"+(-1!==b.indexOf(":")?"["+b+"]":b)+":"+g+c;a.uris.push(e)}}}l.connect(a)};
-    this.subscribe=function(a,b){if("string"!==typeof a&&a.constructor!==Array)throw Error("Invalid argument:"+a);b=b||{};A(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(f(h.INVALID_ARGUMENT,[b.qos,"subscribeOptions.qos"]));l.subscribe(a,b)};this.unsubscribe=function(a,
-    b){if("string"!==typeof a&&a.constructor!==Array)throw Error("Invalid argument:"+a);b=b||{};A(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 w)&&"string"!==typeof a)throw Error("Invalid argument:"+
-    typeof a);e=a;if("undefined"===typeof e.destinationName)throw Error(f(h.INVALID_ARGUMENT,[e.destinationName,"Message.destinationName"]));}else e=new w(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){var e;if(0===arguments.length)throw Error("Invalid argument.length");if(1==arguments.length){if(!(a instanceof w)&&"string"!==typeof a)throw Error("Invalid argument:"+typeof a);e=a;if("undefined"===typeof e.destinationName)throw Error(f(h.INVALID_ARGUMENT,
-    [e.destinationName,"Message.destinationName"]));}else e=new w(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}},Message:w}}("undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:
-    {})});
\ No newline at end of file
+(function(R,y){typeof exports=="object"&&typeof module=="object"?module.exports=y():typeof define=="function"&&define.amd?define(y):typeof exports=="object"?exports=y():R.Paho=y()})(this,function(){var R=function(y){var F="@VERSION@-@BUILDLEVEL@",A=function(){var e={};return{setItem:function(t,n){e[t]=n},getItem:function(t){return e[t]},removeItem:function(t){delete e[t]}}}();try{y.localStorage&&(A=y.localStorage)}catch{}var _={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},x=function(e,t){for(var n in e)if(e.hasOwnProperty(n))if(t.hasOwnProperty(n)){if(typeof e[n]!==t[n])throw new Error(c(a.INVALID_TYPE,[typeof e[n],n]))}else{var s="Unknown property, "+n+". Valid properties are:";for(var o in t)t.hasOwnProperty(o)&&(s=s+" "+o);throw new Error(s)}},w=function(e,t){return function(){return e.apply(t,arguments)}},a={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}."},BUFFER_FULL:{code:18,text:"AMQJS0018E Message buffer is full, maximum buffer size: {0}."}},O={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"},c=function(e,t){var n=e.text;if(t){for(var s,o,r=0;r<t.length;r++)if(s="{"+r+"}",o=n.indexOf(s),o>0){var f=n.substring(0,o),v=n.substring(o+s.length);n=f+t[r]+v}}return n},P=[0,6,77,81,73,115,100,112,3],L=[0,4,77,81,84,84,4],m=function(e,t){this.type=e;for(var n in t)t.hasOwnProperty(n)&&(this[n]=t[n])};m.prototype.encode=function(){var e=(this.type&15)<<4,t=0,n=[],s=0,o;switch(this.messageIdentifier!==void 0&&(t+=2),this.type){case _.CONNECT:switch(this.mqttVersion){case 3:t+=P.length+3;break;case 4:t+=L.length+3;break}t+=p(this.clientId)+2,this.willMessage!==void 0&&(t+=p(this.willMessage.destinationName)+2,o=this.willMessage.payloadBytes,o instanceof Uint8Array||(o=new Uint8Array(f)),t+=o.byteLength+2),this.userName!==void 0&&(t+=p(this.userName)+2),this.password!==void 0&&(t+=p(this.password)+2);break;case _.SUBSCRIBE:e|=2;for(var r=0;r<this.topics.length;r++)n[r]=p(this.topics[r]),t+=n[r]+2;t+=this.requestedQos.length;break;case _.UNSUBSCRIBE:e|=2;for(var r=0;r<this.topics.length;r++)n[r]=p(this.topics[r]),t+=n[r]+2;break;case _.PUBREL:e|=2;break;case _.PUBLISH:this.payloadMessage.duplicate&&(e|=8),e=e|=this.payloadMessage.qos<<1,this.payloadMessage.retained&&(e|=1),s=p(this.payloadMessage.destinationName),t+=s+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 _.DISCONNECT:break;default:break}var v=b(t),l=v.length+1,d=new ArrayBuffer(t+l),h=new Uint8Array(d);if(h[0]=e,h.set(v,1),this.type==_.PUBLISH)l=S(this.payloadMessage.destinationName,s,h,l);else if(this.type==_.CONNECT){switch(this.mqttVersion){case 3:h.set(P,l),l+=P.length;break;case 4:h.set(L,l),l+=L.length;break}var i=0;this.cleanSession&&(i=2),this.willMessage!==void 0&&(i|=4,i|=this.willMessage.qos<<3,this.willMessage.retained&&(i|=32)),this.userName!==void 0&&(i|=128),this.password!==void 0&&(i|=64),h[l++]=i,l=M(this.keepAliveInterval,h,l)}switch(this.messageIdentifier!==void 0&&(l=M(this.messageIdentifier,h,l)),this.type){case _.CONNECT:l=S(this.clientId,p(this.clientId),h,l),this.willMessage!==void 0&&(l=S(this.willMessage.destinationName,p(this.willMessage.destinationName),h,l),l=M(o.byteLength,h,l),h.set(o,l),l+=o.byteLength),this.userName!==void 0&&(l=S(this.userName,p(this.userName),h,l)),this.password!==void 0&&(l=S(this.password,p(this.password),h,l));break;case _.PUBLISH:h.set(f,l);break;case _.SUBSCRIBE:for(var r=0;r<this.topics.length;r++)l=S(this.topics[r],n[r],h,l),h[l++]=this.requestedQos[r];break;case _.UNSUBSCRIBE:for(var r=0;r<this.topics.length;r++)l=S(this.topics[r],n[r],h,l);break;default:}return d};function V(e,t){var n=t,s=e[t],o=s>>4,r=s&=15;t+=1;var f,v=0,l=1;do{if(t==e.length)return[null,n];f=e[t++],v+=(f&127)*l,l*=128}while((f&128)!=0);var d=t+v;if(d>e.length)return[null,n];var h=new m(o);switch(o){case _.CONNACK:var i=e[t++];i&1&&(h.sessionPresent=!0),h.returnCode=e[t++];break;case _.PUBLISH:var E=r>>1&3,g=C(e,t);t+=2;var N=D(e,t,g);t+=g,E>0&&(h.messageIdentifier=C(e,t),t+=2);var I=new T(e.subarray(t,d));(r&1)==1&&(I.retained=!0),(r&8)==8&&(I.duplicate=!0),I.qos=E,I.destinationName=N,h.payloadMessage=I;break;case _.PUBACK:case _.PUBREC:case _.PUBREL:case _.PUBCOMP:case _.UNSUBACK:h.messageIdentifier=C(e,t);break;case _.SUBACK:h.messageIdentifier=C(e,t),t+=2,h.returnCode=e.subarray(t,d);break;default:break}return[h,d]}function M(e,t,n){return t[n++]=e>>8,t[n++]=e%256,n}function S(e,t,n,s){return s=M(t,n,s),k(e,n,s),s+t}function C(e,t){return 256*e[t]+e[t+1]}function b(e){var t=new Array(1),n=0;do{var s=e%128;e=e>>7,e>0&&(s|=128),t[n++]=s}while(e>0&&n<4);return t}function p(e){for(var t=0,n=0;n<e.length;n++){var s=e.charCodeAt(n);s>2047?(55296<=s&&s<=56319&&(n++,t++),t+=3):s>127?t+=2:t++}return t}function k(e,t,n){for(var s=n,o=0;o<e.length;o++){var r=e.charCodeAt(o);if(55296<=r&&r<=56319){var f=e.charCodeAt(++o);if(isNaN(f))throw new Error(c(a.MALFORMED_UNICODE,[r,f]));r=(r-55296<<10)+(f-56320)+65536}r<=127?t[s++]=r:r<=2047?(t[s++]=r>>6&31|192,t[s++]=r&63|128):r<=65535?(t[s++]=r>>12&15|224,t[s++]=r>>6&63|128,t[s++]=r&63|128):(t[s++]=r>>18&7|240,t[s++]=r>>12&63|128,t[s++]=r>>6&63|128,t[s++]=r&63|128)}return t}function D(e,t,n){for(var s="",o,r=t;r<t+n;){var f=e[r++];if(f<128)o=f;else{var v=e[r++]-128;if(v<0)throw new Error(c(a.MALFORMED_UTF,[f.toString(16),v.toString(16),""]));if(f<224)o=64*(f-192)+v;else{var l=e[r++]-128;if(l<0)throw new Error(c(a.MALFORMED_UTF,[f.toString(16),v.toString(16),l.toString(16)]));if(f<240)o=4096*(f-224)+64*v+l;else{var d=e[r++]-128;if(d<0)throw new Error(c(a.MALFORMED_UTF,[f.toString(16),v.toString(16),l.toString(16),d.toString(16)]));if(f<248)o=262144*(f-240)+4096*v+64*l+d;else throw new Error(c(a.MALFORMED_UTF,[f.toString(16),v.toString(16),l.toString(16),d.toString(16)]))}}}o>65535&&(o-=65536,s+=String.fromCharCode(55296+(o>>10)),o=56320+(o&1023)),s+=String.fromCharCode(o)}return s}var B=function(e,t){this._client=e,this._keepAliveInterval=t*1e3,this.isReset=!1;var n=new m(_.PINGREQ).encode(),s=function(r){return function(){return o.apply(r)}},o=function(){this.isReset?(this.isReset=!1,this._client._trace("Pinger.doPing","send PINGREQ"),this._client.socket.send(n),this.timeout=setTimeout(s(this),this._keepAliveInterval)):(this._client._trace("Pinger.doPing","Timed out"),this._client._disconnected(a.PING_TIMEOUT.code,c(a.PING_TIMEOUT)))};this.reset=function(){this.isReset=!0,clearTimeout(this.timeout),this._keepAliveInterval>0&&(this.timeout=setTimeout(s(this),this._keepAliveInterval))},this.cancel=function(){clearTimeout(this.timeout)}},U=function(e,t,n,s){t||(t=30);var o=function(r,f,v){return function(){return r.apply(f,v)}};this.timeout=setTimeout(o(n,e,s),t*1e3),this.cancel=function(){clearTimeout(this.timeout)}},u=function(e,t,n,s,o){if(!("WebSocket"in y&&y.WebSocket!==null))throw new Error(c(a.UNSUPPORTED,["WebSocket"]));if(!("ArrayBuffer"in y&&y.ArrayBuffer!==null))throw new Error(c(a.UNSUPPORTED,["ArrayBuffer"]));this._trace("Paho.Client",e,t,n,s,o),this.host=t,this.port=n,this.path=s,this.uri=e,this.clientId=o,this._wsuri=null,this._localKey=t+":"+n+(s!="/mqtt"?":"+s:"")+":"+o+":",this._msg_queue=[],this._buffered_msg_queue=[],this._sentMessages={},this._receivedMessages={},this._notify_msg_sent={},this._message_identifier=1,this._sequence=0;for(var r in A)(r.indexOf("Sent:"+this._localKey)===0||r.indexOf("Received:"+this._localKey)===0)&&this.restore(r)};u.prototype.host=null,u.prototype.port=null,u.prototype.path=null,u.prototype.uri=null,u.prototype.clientId=null,u.prototype.socket=null,u.prototype.connected=!1,u.prototype.maxMessageIdentifier=65536,u.prototype.connectOptions=null,u.prototype.hostIndex=null,u.prototype.onConnected=null,u.prototype.onConnectionLost=null,u.prototype.onMessageDelivered=null,u.prototype.onMessageArrived=null,u.prototype.traceFunction=null,u.prototype._msg_queue=null,u.prototype._buffered_msg_queue=null,u.prototype._connectTimeout=null,u.prototype.sendPinger=null,u.prototype.receivePinger=null,u.prototype._reconnectInterval=1,u.prototype._reconnecting=!1,u.prototype._reconnectTimeout=null,u.prototype.disconnectedPublishing=!1,u.prototype.disconnectedBufferSize=5e3,u.prototype.receiveBuffer=null,u.prototype._traceBuffer=null,u.prototype._MAX_TRACE_ENTRIES=100,u.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(c(a.INVALID_STATE,["already connected"]));if(this.socket)throw new Error(c(a.INVALID_STATE,["already connected"]));this._reconnecting&&(this._reconnectTimeout.cancel(),this._reconnectTimeout=null,this._reconnecting=!1),this.connectOptions=e,this._reconnectInterval=1,this._reconnecting=!1,e.uris?(this.hostIndex=0,this._doConnect(e.uris[0])):this._doConnect(this.uri)},u.prototype.subscribe=function(e,t){if(this._trace("Client.subscribe",e,t),!this.connected)throw new Error(c(a.INVALID_STATE,["not connected"]));var n=new m(_.SUBSCRIBE);n.topics=e.constructor===Array?e:[e],t.qos===void 0&&(t.qos=0),n.requestedQos=[];for(var s=0;s<n.topics.length;s++)n.requestedQos[s]=t.qos;t.onSuccess&&(n.onSuccess=function(o){t.onSuccess({invocationContext:t.invocationContext,grantedQos:o})}),t.onFailure&&(n.onFailure=function(o){t.onFailure({invocationContext:t.invocationContext,errorCode:o,errorMessage:c(o)})}),t.timeout&&(n.timeOut=new U(this,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:a.SUBSCRIBE_TIMEOUT.code,errorMessage:c(a.SUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},u.prototype.unsubscribe=function(e,t){if(this._trace("Client.unsubscribe",e,t),!this.connected)throw new Error(c(a.INVALID_STATE,["not connected"]));var n=new m(_.UNSUBSCRIBE);n.topics=e.constructor===Array?e:[e],t.onSuccess&&(n.callback=function(){t.onSuccess({invocationContext:t.invocationContext})}),t.timeout&&(n.timeOut=new U(this,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:a.UNSUBSCRIBE_TIMEOUT.code,errorMessage:c(a.UNSUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},u.prototype.send=function(e){this._trace("Client.send",e);var t=new m(_.PUBLISH);if(t.payloadMessage=e,this.connected)e.qos>0?this._requires_ack(t):this.onMessageDelivered&&(this._notify_msg_sent[t]=this.onMessageDelivered(t.payloadMessage)),this._schedule_message(t);else if(this._reconnecting&&this.disconnectedPublishing){var n=Object.keys(this._sentMessages).length+this._buffered_msg_queue.length;if(n>this.disconnectedBufferSize)throw new Error(c(a.BUFFER_FULL,[this.disconnectedBufferSize]));e.qos>0?this._requires_ack(t):(t.sequence=++this._sequence,this._buffered_msg_queue.unshift(t))}else throw new Error(c(a.INVALID_STATE,["not connected"]))},u.prototype.disconnect=function(){if(this._trace("Client.disconnect"),this._reconnecting&&(this._reconnectTimeout.cancel(),this._reconnectTimeout=null,this._reconnecting=!1),!this.socket)throw new Error(c(a.INVALID_STATE,["not connecting or connected"]));var e=new m(_.DISCONNECT);this._notify_msg_sent[e]=w(this._disconnected,this),this._schedule_message(e)},u.prototype.getTraceLog=function(){if(this._traceBuffer!==null){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}},u.prototype.startTrace=function(){this._traceBuffer===null&&(this._traceBuffer=[]),this._trace("Client.startTrace",new Date,F)},u.prototype.stopTrace=function(){delete this._traceBuffer},u.prototype._doConnect=function(e){if(this.connectOptions.useSSL){var t=e.split(":");t[0]="wss",e=t.join(":")}this._wsuri=e,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=w(this._on_socket_open,this),this.socket.onmessage=w(this._on_socket_message,this),this.socket.onerror=w(this._on_socket_error,this),this.socket.onclose=w(this._on_socket_close,this),this.sendPinger=new B(this,this.connectOptions.keepAliveInterval),this.receivePinger=new B(this,this.connectOptions.keepAliveInterval),this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null),this._connectTimeout=new U(this,this.connectOptions.timeout,this._disconnected,[a.CONNECT_TIMEOUT.code,c(a.CONNECT_TIMEOUT)])},u.prototype._schedule_message=function(e){this._msg_queue.unshift(e),this.connected&&this._process_queue()},u.prototype.store=function(e,t){var n={type:t.type,messageIdentifier:t.messageIdentifier,version:1};switch(t.type){case _.PUBLISH:t.pubRecReceived&&(n.pubRecReceived=!0),n.payloadMessage={};for(var s="",o=t.payloadMessage.payloadBytes,r=0;r<o.length;r++)o[r]<=15?s=s+"0"+o[r].toString(16):s=s+o[r].toString(16);n.payloadMessage.payloadHex=s,n.payloadMessage.qos=t.payloadMessage.qos,n.payloadMessage.destinationName=t.payloadMessage.destinationName,t.payloadMessage.duplicate&&(n.payloadMessage.duplicate=!0),t.payloadMessage.retained&&(n.payloadMessage.retained=!0),e.indexOf("Sent:")===0&&(t.sequence===void 0&&(t.sequence=++this._sequence),n.sequence=t.sequence);break;default:throw Error(c(a.INVALID_STORED_DATA,[e+this._localKey+t.messageIdentifier,n]))}A.setItem(e+this._localKey+t.messageIdentifier,JSON.stringify(n))},u.prototype.restore=function(e){var t=A.getItem(e),n=JSON.parse(t),s=new m(n.type,n);switch(n.type){case _.PUBLISH:for(var o=n.payloadMessage.payloadHex,r=new ArrayBuffer(o.length/2),f=new Uint8Array(r),v=0;o.length>=2;){var l=parseInt(o.substring(0,2),16);o=o.substring(2,o.length),f[v++]=l}var d=new T(f);d.qos=n.payloadMessage.qos,d.destinationName=n.payloadMessage.destinationName,n.payloadMessage.duplicate&&(d.duplicate=!0),n.payloadMessage.retained&&(d.retained=!0),s.payloadMessage=d;break;default:throw Error(c(a.INVALID_STORED_DATA,[e,t]))}e.indexOf("Sent:"+this._localKey)===0?(s.payloadMessage.duplicate=!0,this._sentMessages[s.messageIdentifier]=s):e.indexOf("Received:"+this._localKey)===0&&(this._receivedMessages[s.messageIdentifier]=s)},u.prototype._process_queue=function(){for(var e=null;e=this._msg_queue.pop();)this._socket_send(e),this._notify_msg_sent[e]&&(this._notify_msg_sent[e](),delete this._notify_msg_sent[e])},u.prototype._requires_ack=function(e){var t=Object.keys(this._sentMessages).length;if(t>this.maxMessageIdentifier)throw Error("Too many messages:"+t);for(;this._sentMessages[this._message_identifier]!==void 0;)this._message_identifier++;e.messageIdentifier=this._message_identifier,this._sentMessages[e.messageIdentifier]=e,e.type===_.PUBLISH&&this.store("Sent:",e),this._message_identifier===this.maxMessageIdentifier&&(this._message_identifier=1)},u.prototype._on_socket_open=function(){var e=new m(_.CONNECT,this.connectOptions);e.clientId=this.clientId,this._socket_send(e)},u.prototype._on_socket_message=function(e){this._trace("Client._on_socket_message",e.data);for(var t=this._deframeMessages(e.data),n=0;n<t.length;n+=1)this._handleMessage(t[n])},u.prototype._deframeMessages=function(e){var t=new Uint8Array(e),n=[];if(this.receiveBuffer){var s=new Uint8Array(this.receiveBuffer.length+t.length);s.set(this.receiveBuffer),s.set(t,this.receiveBuffer.length),t=s,delete this.receiveBuffer}try{for(var o=0;o<t.length;){var r=V(t,o),f=r[0];if(o=r[1],f!==null)n.push(f);else break}o<t.length&&(this.receiveBuffer=t.subarray(o))}catch(l){var v=l.hasOwnProperty("stack")=="undefined"?l.stack.toString():"No Error Stack Available";this._disconnected(a.INTERNAL_ERROR.code,c(a.INTERNAL_ERROR,[l.message,v]));return}return n},u.prototype._handleMessage=function(e){this._trace("Client._handleMessage",e);try{switch(e.type){case _.CONNACK:if(this._connectTimeout.cancel(),this._reconnectTimeout&&this._reconnectTimeout.cancel(),this.connectOptions.cleanSession){for(var t in this._sentMessages){var d=this._sentMessages[t];A.removeItem("Sent:"+this._localKey+d.messageIdentifier)}this._sentMessages={};for(var t in this._receivedMessages){var h=this._receivedMessages[t];A.removeItem("Received:"+this._localKey+h.messageIdentifier)}this._receivedMessages={}}if(e.returnCode===0)this.connected=!0,this.connectOptions.uris&&(this.hostIndex=this.connectOptions.uris.length);else{this._disconnected(a.CONNACK_RETURNCODE.code,c(a.CONNACK_RETURNCODE,[e.returnCode,O[e.returnCode]]));break}var n=[];for(var s in this._sentMessages)this._sentMessages.hasOwnProperty(s)&&n.push(this._sentMessages[s]);if(this._buffered_msg_queue.length>0)for(var o=null;o=this._buffered_msg_queue.pop();)n.push(o),this.onMessageDelivered&&(this._notify_msg_sent[o]=this.onMessageDelivered(o.payloadMessage));for(var n=n.sort(function(g,N){return g.sequence-N.sequence}),r=0,f=n.length;r<f;r++){var d=n[r];if(d.type==_.PUBLISH&&d.pubRecReceived){var v=new m(_.PUBREL,{messageIdentifier:d.messageIdentifier});this._schedule_message(v)}else this._schedule_message(d)}this.connectOptions.onSuccess&&this.connectOptions.onSuccess({invocationContext:this.connectOptions.invocationContext});var l=!1;this._reconnecting&&(l=!0,this._reconnectInterval=1,this._reconnecting=!1),this._connected(l,this._wsuri),this._process_queue();break;case _.PUBLISH:this._receivePublish(e);break;case _.PUBACK:var d=this._sentMessages[e.messageIdentifier];d&&(delete this._sentMessages[e.messageIdentifier],A.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(d.payloadMessage));break;case _.PUBREC:var d=this._sentMessages[e.messageIdentifier];if(d){d.pubRecReceived=!0;var v=new m(_.PUBREL,{messageIdentifier:e.messageIdentifier});this.store("Sent:",d),this._schedule_message(v)}break;case _.PUBREL:var h=this._receivedMessages[e.messageIdentifier];A.removeItem("Received:"+this._localKey+e.messageIdentifier),h&&(this._receiveMessage(h),delete this._receivedMessages[e.messageIdentifier]);var i=new m(_.PUBCOMP,{messageIdentifier:e.messageIdentifier});this._schedule_message(i);break;case _.PUBCOMP:var d=this._sentMessages[e.messageIdentifier];delete this._sentMessages[e.messageIdentifier],A.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(d.payloadMessage);break;case _.SUBACK:var d=this._sentMessages[e.messageIdentifier];d&&(d.timeOut&&d.timeOut.cancel(),e.returnCode[0]===128?d.onFailure&&d.onFailure(e.returnCode):d.onSuccess&&d.onSuccess(e.returnCode),delete this._sentMessages[e.messageIdentifier]);break;case _.UNSUBACK:var d=this._sentMessages[e.messageIdentifier];d&&(d.timeOut&&d.timeOut.cancel(),d.callback&&d.callback(),delete this._sentMessages[e.messageIdentifier]);break;case _.PINGRESP:this.sendPinger.reset();break;case _.DISCONNECT:this._disconnected(a.INVALID_MQTT_MESSAGE_TYPE.code,c(a.INVALID_MQTT_MESSAGE_TYPE,[e.type]));break;default:this._disconnected(a.INVALID_MQTT_MESSAGE_TYPE.code,c(a.INVALID_MQTT_MESSAGE_TYPE,[e.type]))}}catch(g){var E=g.hasOwnProperty("stack")=="undefined"?g.stack.toString():"No Error Stack Available";this._disconnected(a.INTERNAL_ERROR.code,c(a.INTERNAL_ERROR,[g.message,E]));return}},u.prototype._on_socket_error=function(e){this._reconnecting||this._disconnected(a.SOCKET_ERROR.code,c(a.SOCKET_ERROR,[e.data]))},u.prototype._on_socket_close=function(){this._reconnecting||this._disconnected(a.SOCKET_CLOSE.code,c(a.SOCKET_CLOSE))},u.prototype._socket_send=function(e){if(e.type==1){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()},u.prototype._receivePublish=function(e){switch(e.payloadMessage.qos){case"undefined":case 0:this._receiveMessage(e);break;case 1:var t=new m(_.PUBACK,{messageIdentifier:e.messageIdentifier});this._schedule_message(t),this._receiveMessage(e);break;case 2:this._receivedMessages[e.messageIdentifier]=e,this.store("Received:",e);var n=new m(_.PUBREC,{messageIdentifier:e.messageIdentifier});this._schedule_message(n);break;default:throw Error("Invaild qos="+e.payloadMessage.qos)}},u.prototype._receiveMessage=function(e){this.onMessageArrived&&this.onMessageArrived(e.payloadMessage)},u.prototype._connected=function(e,t){this.onConnected&&this.onConnected(e,t)},u.prototype._reconnect=function(){this._trace("Client._reconnect"),this.connected||(this._reconnecting=!0,this.sendPinger.cancel(),this.receivePinger.cancel(),this._reconnectInterval<128&&(this._reconnectInterval=this._reconnectInterval*2),this.connectOptions.uris?(this.hostIndex=0,this._doConnect(this.connectOptions.uris[0])):this._doConnect(this.uri))},u.prototype._disconnected=function(e,t){if(this._trace("Client._disconnected",e,t),e!==void 0&&this._reconnecting){this._reconnectTimeout=new U(this,this._reconnectInterval,this._reconnect);return}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.socket&&(this.socket.onopen=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.onclose=null,this.socket.readyState===1&&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]);else if(e===void 0&&(e=a.OK.code,t=c(a.OK)),this.connected){if(this.connected=!1,this.onConnectionLost&&this.onConnectionLost({errorCode:e,errorMessage:t,reconnect:this.connectOptions.reconnect,uri:this._wsuri}),e!==a.OK.code&&this.connectOptions.reconnect){this._reconnectInterval=1,this._reconnect();return}}else this.connectOptions.mqttVersion===4&&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})},u.prototype._trace=function(){if(this.traceFunction){var e=Array.prototype.slice.call(arguments);for(var t in e)typeof e[t]!="undefined"&&e.splice(t,1,JSON.stringify(e[t]));var n=e.join("");this.traceFunction({severity:"Debug",message:n})}if(this._traceBuffer!==null)for(var t=0,s=arguments.length;t<s;t++)this._traceBuffer.length==this._MAX_TRACE_ENTRIES&&this._traceBuffer.shift(),t===0?this._traceBuffer.push(arguments[t]):typeof arguments[t]=="undefined"?this._traceBuffer.push(arguments[t]):this._traceBuffer.push("  "+JSON.stringify(arguments[t]))},u.prototype._traceMask=function(e,t){var n={};for(var s in e)e.hasOwnProperty(s)&&(s==t?n[s]="******":n[s]=e[s]);return n};var K=function(e,t,n,s){var o;if(typeof e!="string")throw new Error(c(a.INVALID_TYPE,[typeof e,"host"]));if(arguments.length==2){s=t,o=e;var r=o.match(/^(wss?):\/\/((\[(.+)\])|([^\/]+?))(:(\d+))?(\/.*)$/);if(r)e=r[4]||r[2],t=parseInt(r[7]),n=r[8];else throw new Error(c(a.INVALID_ARGUMENT,[e,"host"]))}else{if(arguments.length==3&&(s=n,n="/mqtt"),typeof t!="number"||t<0)throw new Error(c(a.INVALID_TYPE,[typeof t,"port"]));if(typeof n!="string")throw new Error(c(a.INVALID_TYPE,[typeof n,"path"]));var f=e.indexOf(":")!==-1&&e.slice(0,1)!=="["&&e.slice(-1)!=="]";o="ws://"+(f?"["+e+"]":e)+":"+t+n}for(var v=0,l=0;l<s.length;l++){var d=s.charCodeAt(l);55296<=d&&d<=56319&&l++,v++}if(typeof s!="string"||v>65535)throw new Error(c(a.INVALID_ARGUMENT,[s,"clientId"]));var h=new u(o,e,t,n,s);Object.defineProperties(this,{host:{get:function(){return e},set:function(){throw new Error(c(a.UNSUPPORTED_OPERATION))}},port:{get:function(){return t},set:function(){throw new Error(c(a.UNSUPPORTED_OPERATION))}},path:{get:function(){return n},set:function(){throw new Error(c(a.UNSUPPORTED_OPERATION))}},uri:{get:function(){return o},set:function(){throw new Error(c(a.UNSUPPORTED_OPERATION))}},clientId:{get:function(){return h.clientId},set:function(){throw new Error(c(a.UNSUPPORTED_OPERATION))}},onConnected:{get:function(){return h.onConnected},set:function(i){if(typeof i=="function")h.onConnected=i;else throw new Error(c(a.INVALID_TYPE,[typeof i,"onConnected"]))}},disconnectedPublishing:{get:function(){return h.disconnectedPublishing},set:function(i){h.disconnectedPublishing=i}},disconnectedBufferSize:{get:function(){return h.disconnectedBufferSize},set:function(i){h.disconnectedBufferSize=i}},onConnectionLost:{get:function(){return h.onConnectionLost},set:function(i){if(typeof i=="function")h.onConnectionLost=i;else throw new Error(c(a.INVALID_TYPE,[typeof i,"onConnectionLost"]))}},onMessageDelivered:{get:function(){return h.onMessageDelivered},set:function(i){if(typeof i=="function")h.onMessageDelivered=i;else throw new Error(c(a.INVALID_TYPE,[typeof i,"onMessageDelivered"]))}},onMessageArrived:{get:function(){return h.onMessageArrived},set:function(i){if(typeof i=="function")h.onMessageArrived=i;else throw new Error(c(a.INVALID_TYPE,[typeof i,"onMessageArrived"]))}},trace:{get:function(){return h.traceFunction},set:function(i){if(typeof i=="function")h.traceFunction=i;else throw new Error(c(a.INVALID_TYPE,[typeof i,"onTrace"]))}}}),this.connect=function(i){if(i=i||{},x(i,{timeout:"number",userName:"string",password:"string",willMessage:"object",keepAliveInterval:"number",cleanSession:"boolean",useSSL:"boolean",invocationContext:"object",onSuccess:"function",onFailure:"function",hosts:"object",ports:"object",reconnect:"boolean",mqttVersion:"number",mqttVersionExplicit:"boolean",uris:"object"}),i.keepAliveInterval===void 0&&(i.keepAliveInterval=60),i.mqttVersion>4||i.mqttVersion<3)throw new Error(c(a.INVALID_ARGUMENT,[i.mqttVersion,"connectOptions.mqttVersion"]));if(i.mqttVersion===void 0?(i.mqttVersionExplicit=!1,i.mqttVersion=4):i.mqttVersionExplicit=!0,i.password!==void 0&&i.userName===void 0)throw new Error(c(a.INVALID_ARGUMENT,[i.password,"connectOptions.password"]));if(i.willMessage){if(!(i.willMessage instanceof T))throw new Error(c(a.INVALID_TYPE,[i.willMessage,"connectOptions.willMessage"]));if(i.willMessage.stringPayload=null,typeof i.willMessage.destinationName=="undefined")throw new Error(c(a.INVALID_TYPE,[typeof i.willMessage.destinationName,"connectOptions.willMessage.destinationName"]))}if(typeof i.cleanSession=="undefined"&&(i.cleanSession=!0),i.hosts){if(!(i.hosts instanceof Array))throw new Error(c(a.INVALID_ARGUMENT,[i.hosts,"connectOptions.hosts"]));if(i.hosts.length<1)throw new Error(c(a.INVALID_ARGUMENT,[i.hosts,"connectOptions.hosts"]));for(var E=!1,g=0;g<i.hosts.length;g++){if(typeof i.hosts[g]!="string")throw new Error(c(a.INVALID_TYPE,[typeof i.hosts[g],"connectOptions.hosts["+g+"]"]));if(/^(wss?):\/\/((\[(.+)\])|([^\/]+?))(:(\d+))?(\/.*)$/.test(i.hosts[g])){if(g===0)E=!0;else if(!E)throw new Error(c(a.INVALID_ARGUMENT,[i.hosts[g],"connectOptions.hosts["+g+"]"]))}else if(E)throw new Error(c(a.INVALID_ARGUMENT,[i.hosts[g],"connectOptions.hosts["+g+"]"]))}if(E)i.uris=i.hosts;else{if(!i.ports)throw new Error(c(a.INVALID_ARGUMENT,[i.ports,"connectOptions.ports"]));if(!(i.ports instanceof Array))throw new Error(c(a.INVALID_ARGUMENT,[i.ports,"connectOptions.ports"]));if(i.hosts.length!==i.ports.length)throw new Error(c(a.INVALID_ARGUMENT,[i.ports,"connectOptions.ports"]));i.uris=[];for(var g=0;g<i.hosts.length;g++){if(typeof i.ports[g]!="number"||i.ports[g]<0)throw new Error(c(a.INVALID_TYPE,[typeof i.ports[g],"connectOptions.ports["+g+"]"]));var N=i.hosts[g],I=i.ports[g],G=N.indexOf(":")!==-1;o="ws://"+(G?"["+N+"]":N)+":"+I+n,i.uris.push(o)}}}h.connect(i)},this.subscribe=function(i,E){if(typeof i!="string"&&i.constructor!==Array)throw new Error("Invalid argument:"+i);if(E=E||{},x(E,{qos:"number",invocationContext:"object",onSuccess:"function",onFailure:"function",timeout:"number"}),E.timeout&&!E.onFailure)throw new Error("subscribeOptions.timeout specified with no onFailure callback.");if(typeof E.qos!="undefined"&&!(E.qos===0||E.qos===1||E.qos===2))throw new Error(c(a.INVALID_ARGUMENT,[E.qos,"subscribeOptions.qos"]));h.subscribe(i,E)},this.unsubscribe=function(i,E){if(typeof i!="string"&&i.constructor!==Array)throw new Error("Invalid argument:"+i);if(E=E||{},x(E,{invocationContext:"object",onSuccess:"function",onFailure:"function",timeout:"number"}),E.timeout&&!E.onFailure)throw new Error("unsubscribeOptions.timeout specified with no onFailure callback.");h.unsubscribe(i,E)},this.send=function(i,E,g,N){var I;if(arguments.length===0)throw new Error("Invalid argument.length");if(arguments.length==1){if(!(i instanceof T)&&typeof i!="string")throw new Error("Invalid argument:"+typeof i);if(I=i,typeof I.destinationName=="undefined")throw new Error(c(a.INVALID_ARGUMENT,[I.destinationName,"Message.destinationName"]));h.send(I)}else I=new T(E),I.destinationName=i,arguments.length>=3&&(I.qos=g),arguments.length>=4&&(I.retained=N),h.send(I)},this.publish=function(i,E,g,N){var I;if(arguments.length===0)throw new Error("Invalid argument.length");if(arguments.length==1){if(!(i instanceof T)&&typeof i!="string")throw new Error("Invalid argument:"+typeof i);if(I=i,typeof I.destinationName=="undefined")throw new Error(c(a.INVALID_ARGUMENT,[I.destinationName,"Message.destinationName"]));h.send(I)}else I=new T(E),I.destinationName=i,arguments.length>=3&&(I.qos=g),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}},T=function(e){var t;if(typeof e=="string"||e instanceof ArrayBuffer||ArrayBuffer.isView(e)&&!(e instanceof DataView))t=e;else throw c(a.INVALID_ARGUMENT,[e,"newPayload"]);var n,s=0,o=!1,r=!1;Object.defineProperties(this,{payloadString:{enumerable:!0,get:function(){return typeof t=="string"?t:D(t,0,t.length)}},payloadBytes:{enumerable:!0,get:function(){if(typeof t=="string"){var f=new ArrayBuffer(p(t)),v=new Uint8Array(f);return k(t,v,0),v}else return t}},destinationName:{enumerable:!0,get:function(){return n},set:function(f){if(typeof f=="string")n=f;else throw new Error(c(a.INVALID_ARGUMENT,[f,"newDestinationName"]))}},qos:{enumerable:!0,get:function(){return s},set:function(f){if(f===0||f===1||f===2)s=f;else throw new Error("Invalid argument:"+f)}},retained:{enumerable:!0,get:function(){return o},set:function(f){if(typeof f=="boolean")o=f;else throw new Error(c(a.INVALID_ARGUMENT,[f,"newRetained"]))}},topic:{enumerable:!0,get:function(){return n},set:function(f){n=f}},duplicate:{enumerable:!0,get:function(){return r},set:function(f){r=f}}})};return{Client:K,Message:T}}(typeof global!="undefined"?global:typeof self!="undefined"?self:typeof window!="undefined"?window:{});return R});
diff --git a/paho-mqtt.js b/paho-mqtt.js
index 9ca3d37bc9938f56e2618cced0476e19b330f7dc..aefa4fab58f02d4c25d403cf306c121d700f65c0 100644
--- a/paho-mqtt.js
+++ b/paho-mqtt.js
@@ -106,7 +106,7 @@ function onMessageArrived(message) {
 	/**
 	 * @private
 	 */
-	var localStorage = global.localStorage || (function () {
+	var localStorage = (function () {
 		var data = {};
 
 		return {
@@ -115,6 +115,14 @@ function onMessageArrived(message) {
 			removeItem: function (key) { delete data[key]; },
 		};
 	})();
+	try {
+		if (global.localStorage) {
+			localStorage = global.localStorage;
+		}
+	} catch (err) {
+		// in browsers localStorage access can be disabled / blocked and even
+		// reading the localStorage property will result in an Access denied error
+	}
 
 		/**
 	 * Unique message type identifiers, with associated

Make sure paho-mqtt is installed. Then add this to your project’s package.json:

  "resolutions": {
    "paho-mqtt": "patch:paho-mqtt@npm:1.1.0#.yarn/patches/paho-mqtt-npm-1.1.0-c2bf8169e8"
  }

Finally, run yarn to apply the patch and it’s done! Anytime anyone clones your project and runs yarn, it’ll take care of patching this for you.