Skip to content

Commit 84ca344

Browse files
scarry1992mcollina
andcommitted
process disconnect packet w/o full destroy the connection (#937)
* process disconnect packet w/o full destroy the connection * Update README.md Co-Authored-By: Matteo Collina <matteo.collina@gmail.com>
1 parent e8de240 commit 84ca344

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ Emitted when a reconnect starts.
291291

292292
Emitted after a disconnection.
293293

294+
#### Event `'disconnect'`
295+
296+
`function (packet) {}`
297+
298+
Emitted after receiving disconnect packet from broker. MQTT 5.0 feature.
299+
294300
#### Event `'offline'`
295301

296302
`function () {}`

‎lib/client.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,7 @@ MqttClient.prototype._handlePubrel = function (packet, callback) {
12771277
* @api private
12781278
*/
12791279
MqttClient.prototype._handleDisconnect = function (packet) {
1280-
this.emit('close', packet)
1281-
this.end(true)
1280+
this.emit('disconnect', packet)
12821281
}
12831282

12841283
/**

‎test/client.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ describe('MqttClient', function () {
953953
}
954954

955955
var client = mqtt.connect(opts)
956-
client.once('close', function (disconnectPacket) {
956+
client.once('disconnect', function (disconnectPacket) {
957957
should(disconnectPacket.reasonCode).be.equal(128)
958958
done()
959959
})

0 commit comments

Comments
 (0)