Skip to content

Commit

Permalink
process disconnect packet w/o full destroy the connection (#937)
Browse files Browse the repository at this point in the history
* process disconnect packet w/o full destroy the connection

* Update README.md

Co-Authored-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
scarry1992 and mcollina committed May 14, 2019
1 parent e8de240 commit 84ca344
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -291,6 +291,12 @@ Emitted when a reconnect starts.

Emitted after a disconnection.

#### Event `'disconnect'`

`function (packet) {}`

Emitted after receiving disconnect packet from broker. MQTT 5.0 feature.

#### Event `'offline'`

`function () {}`
Expand Down
3 changes: 1 addition & 2 deletions lib/client.js
Expand Up @@ -1277,8 +1277,7 @@ MqttClient.prototype._handlePubrel = function (packet, callback) {
* @api private
*/
MqttClient.prototype._handleDisconnect = function (packet) {
this.emit('close', packet)
this.end(true)
this.emit('disconnect', packet)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/client.js
Expand Up @@ -953,7 +953,7 @@ describe('MqttClient', function () {
}

var client = mqtt.connect(opts)
client.once('close', function (disconnectPacket) {
client.once('disconnect', function (disconnectPacket) {
should(disconnectPacket.reasonCode).be.equal(128)
done()
})
Expand Down

0 comments on commit 84ca344

Please sign in to comment.