mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Improve MQTT broker disconnect situation
* Ensure topic is sane to prevent error 129 * Ensure a log entry is made * Update node status
This commit is contained in:
@@ -288,7 +288,7 @@ module.exports = function(RED) {
|
||||
//TODO: delete msg.responseTopic - to prevent it being resent?
|
||||
}
|
||||
}
|
||||
topicOK = topicOK && !/[\+#]/.test(msg.topic);
|
||||
topicOK = topicOK && !/[\+#\b\f\n\r\t\v\0]/.test(msg.topic);
|
||||
|
||||
if (topicOK) {
|
||||
node.brokerConn.publish(msg, done); // send the message
|
||||
@@ -730,12 +730,18 @@ module.exports = function(RED) {
|
||||
node.client.on("reconnect", function() {
|
||||
setStatusConnecting(node, true);
|
||||
});
|
||||
//TODO: what to do with this event? Anything? Necessary?
|
||||
//Broker Disconnect - V5 event
|
||||
node.client.on("disconnect", function(packet) {
|
||||
//Emitted after receiving disconnect packet from broker. MQTT 5.0 feature.
|
||||
var rc = packet && packet.properties && packet.properties.reasonString;
|
||||
var rc = packet && packet.properties && packet.reasonCode;
|
||||
//TODO: If keeping this event, do we use these? log these?
|
||||
const rc = (packet && packet.properties && packet.reasonCode) || packet.reasonCode;
|
||||
const rs = packet && packet.properties && packet.properties.reasonString || "";
|
||||
const details = {
|
||||
broker: (node.clientid?node.clientid+"@":"")+node.brokerurl,
|
||||
reasonCode: rc,
|
||||
reasonString: rs
|
||||
}
|
||||
node.log(RED._("mqtt.state.broker-disconnected", details));
|
||||
setStatusDisconnected(node, true);
|
||||
});
|
||||
// Register disconnect handlers
|
||||
node.client.on('close', function () {
|
||||
|
Reference in New Issue
Block a user