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 +15 -6
- package/dist/mqtt.min.js +1 -1
- package/lib/client.js +15 -6
- package/package.json +1 -1
- package/test/abstract_client.js +109 -0
package/lib/client.js
CHANGED
|
@@ -954,6 +954,7 @@ default:
|
|
|
954
954
|
for now i just suppressed the warnings
|
|
955
955
|
*/
|
|
956
956
|
MqttClient.prototype._handlePublish = function (packet, done) {
|
|
957
|
+
done = typeof done !== 'undefined' ? done : nop
|
|
957
958
|
var topic = packet.topic.toString()
|
|
958
959
|
var message = packet.payload
|
|
959
960
|
var qos = packet.qos
|
|
@@ -962,7 +963,10 @@ MqttClient.prototype._handlePublish = function (packet, done) {
|
|
|
962
963
|
|
|
963
964
|
switch (qos) {
|
|
964
965
|
case 2:
|
|
965
|
-
this.incomingStore.put(packet, function () {
|
|
966
|
+
this.incomingStore.put(packet, function (err) {
|
|
967
|
+
if (err) {
|
|
968
|
+
return done(err)
|
|
969
|
+
}
|
|
966
970
|
that._sendPacket({cmd: 'pubrec', messageId: mid}, done)
|
|
967
971
|
})
|
|
968
972
|
break
|
|
@@ -971,7 +975,7 @@ MqttClient.prototype._handlePublish = function (packet, done) {
|
|
|
971
975
|
this.emit('message', topic, message, packet)
|
|
972
976
|
this.handleMessage(packet, function (err) {
|
|
973
977
|
if (err) {
|
|
974
|
-
return done
|
|
978
|
+
return done(err)
|
|
975
979
|
}
|
|
976
980
|
// send 'puback' if the above 'handleMessage' method executed
|
|
977
981
|
// successfully.
|
|
@@ -1074,6 +1078,7 @@ MqttClient.prototype._handleAck = function (packet) {
|
|
|
1074
1078
|
* @api private
|
|
1075
1079
|
*/
|
|
1076
1080
|
MqttClient.prototype._handlePubrel = function (packet, callback) {
|
|
1081
|
+
callback = typeof callback !== 'undefined' ? callback : nop
|
|
1077
1082
|
var mid = packet.messageId
|
|
1078
1083
|
var that = this
|
|
1079
1084
|
|
|
@@ -1082,12 +1087,16 @@ MqttClient.prototype._handlePubrel = function (packet, callback) {
|
|
|
1082
1087
|
that.incomingStore.get(packet, function (err, pub) {
|
|
1083
1088
|
if (!err && pub.cmd !== 'pubrel') {
|
|
1084
1089
|
that.emit('message', pub.topic, pub.payload, pub)
|
|
1085
|
-
that.incomingStore.put(packet)
|
|
1086
|
-
that.handleMessage(pub, function (err) {
|
|
1090
|
+
that.incomingStore.put(packet, function (err) {
|
|
1087
1091
|
if (err) {
|
|
1088
|
-
return callback
|
|
1092
|
+
return callback(err)
|
|
1089
1093
|
}
|
|
1090
|
-
that.
|
|
1094
|
+
that.handleMessage(pub, function (err) {
|
|
1095
|
+
if (err) {
|
|
1096
|
+
return callback(err)
|
|
1097
|
+
}
|
|
1098
|
+
that._sendPacket(comp, callback)
|
|
1099
|
+
})
|
|
1091
1100
|
})
|
|
1092
1101
|
} else {
|
|
1093
1102
|
that._sendPacket(comp, callback)
|
package/package.json
CHANGED
package/test/abstract_client.js
CHANGED
|
@@ -973,6 +973,115 @@ module.exports = function (server, config) {
|
|
|
973
973
|
}
|
|
974
974
|
})
|
|
975
975
|
|
|
976
|
+
it('should handle error with async incoming store in QoS 2 `handlePublish` method', function (done) {
|
|
977
|
+
function AsyncStore () {
|
|
978
|
+
if (!(this instanceof AsyncStore)) {
|
|
979
|
+
return new AsyncStore()
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
AsyncStore.prototype.put = function (packet, cb) {
|
|
983
|
+
process.nextTick(function () {
|
|
984
|
+
cb(new Error('Error'))
|
|
985
|
+
})
|
|
986
|
+
}
|
|
987
|
+
var store = new AsyncStore()
|
|
988
|
+
var client = connect({incomingStore: store})
|
|
989
|
+
|
|
990
|
+
client._handlePublish({
|
|
991
|
+
messageId: 1,
|
|
992
|
+
topic: 'test',
|
|
993
|
+
payload: 'test',
|
|
994
|
+
qos: 2
|
|
995
|
+
}, function () {
|
|
996
|
+
done()
|
|
997
|
+
client.end()
|
|
998
|
+
})
|
|
999
|
+
})
|
|
1000
|
+
|
|
1001
|
+
it('should handle error with async incoming store in QoS 2 `handlePubrel` method', function (done) {
|
|
1002
|
+
function AsyncStore () {
|
|
1003
|
+
if (!(this instanceof AsyncStore)) {
|
|
1004
|
+
return new AsyncStore()
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
AsyncStore.prototype.put = function (packet, cb) {
|
|
1008
|
+
process.nextTick(function () {
|
|
1009
|
+
cb(new Error('Error'))
|
|
1010
|
+
})
|
|
1011
|
+
}
|
|
1012
|
+
AsyncStore.prototype.get = function (packet, cb) {
|
|
1013
|
+
process.nextTick(function () {
|
|
1014
|
+
cb(null, {cmd: 'publish'})
|
|
1015
|
+
})
|
|
1016
|
+
}
|
|
1017
|
+
var store = new AsyncStore()
|
|
1018
|
+
var client = connect({incomingStore: store})
|
|
1019
|
+
|
|
1020
|
+
client._handlePubrel({
|
|
1021
|
+
messageId: 1,
|
|
1022
|
+
qos: 2
|
|
1023
|
+
}, function () {
|
|
1024
|
+
done()
|
|
1025
|
+
client.end()
|
|
1026
|
+
})
|
|
1027
|
+
})
|
|
1028
|
+
|
|
1029
|
+
it('should handle success with async incoming store in QoS 2 `handlePubrel` method', function (done) {
|
|
1030
|
+
var putComplete = false
|
|
1031
|
+
function AsyncStore () {
|
|
1032
|
+
if (!(this instanceof AsyncStore)) {
|
|
1033
|
+
return new AsyncStore()
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
AsyncStore.prototype.put = function (packet, cb) {
|
|
1037
|
+
process.nextTick(function () {
|
|
1038
|
+
putComplete = true
|
|
1039
|
+
cb(null)
|
|
1040
|
+
})
|
|
1041
|
+
}
|
|
1042
|
+
AsyncStore.prototype.get = function (packet, cb) {
|
|
1043
|
+
process.nextTick(function () {
|
|
1044
|
+
cb(null, {cmd: 'publish'})
|
|
1045
|
+
})
|
|
1046
|
+
}
|
|
1047
|
+
var store = new AsyncStore()
|
|
1048
|
+
var client = connect({incomingStore: store})
|
|
1049
|
+
|
|
1050
|
+
client._handlePubrel({
|
|
1051
|
+
messageId: 1,
|
|
1052
|
+
qos: 2
|
|
1053
|
+
}, function () {
|
|
1054
|
+
putComplete.should.equal(true)
|
|
1055
|
+
done()
|
|
1056
|
+
client.end()
|
|
1057
|
+
})
|
|
1058
|
+
})
|
|
1059
|
+
|
|
1060
|
+
it('should handle error with async incoming store in QoS 1 `handlePublish` method', function (done) {
|
|
1061
|
+
function AsyncStore () {
|
|
1062
|
+
if (!(this instanceof AsyncStore)) {
|
|
1063
|
+
return new AsyncStore()
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
AsyncStore.prototype.put = function (packet, cb) {
|
|
1067
|
+
process.nextTick(function () {
|
|
1068
|
+
cb(null, 'Error')
|
|
1069
|
+
})
|
|
1070
|
+
}
|
|
1071
|
+
var store = new AsyncStore()
|
|
1072
|
+
var client = connect({incomingStore: store})
|
|
1073
|
+
|
|
1074
|
+
client._handlePublish({
|
|
1075
|
+
messageId: 1,
|
|
1076
|
+
topic: 'test',
|
|
1077
|
+
payload: 'test',
|
|
1078
|
+
qos: 1
|
|
1079
|
+
}, function () {
|
|
1080
|
+
done()
|
|
1081
|
+
client.end()
|
|
1082
|
+
})
|
|
1083
|
+
})
|
|
1084
|
+
|
|
976
1085
|
it('should not send a `pubcomp` if the execution of `handleMessage` fails for messages with QoS `2`', function (done) {
|
|
977
1086
|
var store = new Store()
|
|
978
1087
|
var client = connect({incomingStore: store})
|