Skip to content

Commit 456593d

Browse files
committed
Calling client.end() when detaching the element
This implements #14
1 parent fb2aaf5 commit 456593d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

mqtt-connection.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@
262262

263263
},
264264

265+
_createdConnection: false,
266+
265267
observers: [
266268
'_usernameOrPasswordChanged(username, options.username, password, options.password, withCredentials, auto)',
267269
'_autoChanged(auto, withCredentials)'
@@ -280,6 +282,12 @@
280282
}
281283
},
282284

285+
detached: function () {
286+
if (this._createdConnection && this.client){
287+
this.disconnect();
288+
}
289+
},
290+
283291
_usernameChanged: function (username, old) {
284292
this.set("options.username", username);
285293
},
@@ -443,10 +451,13 @@
443451
if (this.options.clientId && this.options.clientId.length == 0){
444452
this.set("options.clientId", this._generateClientId());
445453
}
454+
446455
this.options["queue"] = this.packetQueue;
447456

448457
this.client = mqtt.connect(this.url, this.options);
449458
this.client.setMaxListeners(this.maxListeners);
459+
460+
this._createdConnection = true;
450461
},
451462

452463
/**

0 commit comments

Comments
 (0)