Skip to content

Commit

Permalink
Fix #2 always publish even when disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
mblackstock committed Feb 16, 2019
1 parent d2830e5 commit 0949de6
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions mqttdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,26 +304,25 @@ module.exports = function (RED) {
};

this.publish = function (msg) {
if (node.connected) {
if (!Buffer.isBuffer(msg.payload)) {
if (typeof msg.payload === "object") {
msg.payload = JSON.stringify(msg.payload);
} else if (typeof msg.payload !== "string") {
msg.payload = "" + msg.payload;
}
// always publish in case we are temporarily disconnected
if (!Buffer.isBuffer(msg.payload)) {
if (typeof msg.payload === "object") {
msg.payload = JSON.stringify(msg.payload);
} else if (typeof msg.payload !== "string") {
msg.payload = "" + msg.payload;
}

var options = {
qos: msg.qos || 0,
retain: msg.retain || false
};
node.client.publish(msg.topic, msg.payload, options, function (err) {
if (err) {
node.error("error publishing message: " + err.toString());
}
return
});
}

var options = {
qos: msg.qos || 0,
retain: msg.retain || false
};
node.client.publish(msg.topic, msg.payload, options, function (err) {
if (err) {
node.error("error publishing message: " + err.toString());
}
return
});
};

function deleteStore(removed, done) {
Expand Down

0 comments on commit 0949de6

Please sign in to comment.