diff --git a/mqtt-connection.html b/mqtt-connection.html
index b74f795..8424c79 100644
--- a/mqtt-connection.html
+++ b/mqtt-connection.html
@@ -262,6 +262,8 @@
},
+ _createdConnection: false,
+
observers: [
'_usernameOrPasswordChanged(username, options.username, password, options.password, withCredentials, auto)',
'_autoChanged(auto, withCredentials)'
@@ -280,6 +282,12 @@
}
},
+ detached: function () {
+ if (this._createdConnection && this.client){
+ this.disconnect();
+ }
+ },
+
_usernameChanged: function (username, old) {
this.set("options.username", username);
},
@@ -443,10 +451,13 @@
if (this.options.clientId && this.options.clientId.length == 0){
this.set("options.clientId", this._generateClientId());
}
+
this.options["queue"] = this.packetQueue;
this.client = mqtt.connect(this.url, this.options);
this.client.setMaxListeners(this.maxListeners);
+
+ this._createdConnection = true;
},
/**