mqtt 2.18.7 → 2.18.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mqtt.js CHANGED
@@ -956,6 +956,7 @@ default:
956
956
  for now i just suppressed the warnings
957
957
  */
958
958
  MqttClient.prototype._handlePublish = function (packet, done) {
959
+ done = typeof done !== 'undefined' ? done : nop
959
960
  var topic = packet.topic.toString()
960
961
  var message = packet.payload
961
962
  var qos = packet.qos
@@ -964,7 +965,10 @@ MqttClient.prototype._handlePublish = function (packet, done) {
964
965
 
965
966
  switch (qos) {
966
967
  case 2:
967
- this.incomingStore.put(packet, function () {
968
+ this.incomingStore.put(packet, function (err) {
969
+ if (err) {
970
+ return done(err)
971
+ }
968
972
  that._sendPacket({cmd: 'pubrec', messageId: mid}, done)
969
973
  })
970
974
  break
@@ -973,7 +977,7 @@ MqttClient.prototype._handlePublish = function (packet, done) {
973
977
  this.emit('message', topic, message, packet)
974
978
  this.handleMessage(packet, function (err) {
975
979
  if (err) {
976
- return done && done(err)
980
+ return done(err)
977
981
  }
978
982
  // send 'puback' if the above 'handleMessage' method executed
979
983
  // successfully.
@@ -1076,6 +1080,7 @@ MqttClient.prototype._handleAck = function (packet) {
1076
1080
  * @api private
1077
1081
  */
1078
1082
  MqttClient.prototype._handlePubrel = function (packet, callback) {
1083
+ callback = typeof callback !== 'undefined' ? callback : nop
1079
1084
  var mid = packet.messageId
1080
1085
  var that = this
1081
1086
 
@@ -1084,12 +1089,16 @@ MqttClient.prototype._handlePubrel = function (packet, callback) {
1084
1089
  that.incomingStore.get(packet, function (err, pub) {
1085
1090
  if (!err && pub.cmd !== 'pubrel') {
1086
1091
  that.emit('message', pub.topic, pub.payload, pub)
1087
- that.incomingStore.put(packet)
1088
- that.handleMessage(pub, function (err) {
1092
+ that.incomingStore.put(packet, function (err) {
1089
1093
  if (err) {
1090
- return callback && callback(err)
1094
+ return callback(err)
1091
1095
  }
1092
- that._sendPacket(comp, callback)
1096
+ that.handleMessage(pub, function (err) {
1097
+ if (err) {
1098
+ return callback(err)
1099
+ }
1100
+ that._sendPacket(comp, callback)
1101
+ })
1093
1102
  })
1094
1103
  } else {
1095
1104
  that._sendPacket(comp, callback)