Skip to content

Commit

Permalink
[fix] Fix map set sending values to client instead of broker
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Jun 19, 2019
1 parent c3556f8 commit 93bd7f8
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions lib/broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async function init() {

config = settings.broker || {};

if(!config.port) config.port = 1884;
if (!config.port) config.port = 1884;

if (config.ssl) {
var now = new Date();
Expand All @@ -123,7 +123,7 @@ async function init() {
certs.expireDate = now;

await jsonStore.put(store.certs, certs);
}else{
} else {
config._key = certs.key;
config._cert = certs.cert;
}
Expand Down Expand Up @@ -215,7 +215,6 @@ function initClient(c) {

// subscribe for write requests
mapsSet.forEach(m => {
m.client = client;
client.subscribe(m.wFrom);
});

Expand All @@ -225,7 +224,6 @@ function initClient(c) {

values.forEach(v => {
v.map = settings.maps.find(m => m._id == v.map_id);
v.client = client;
if (v.map) { // if there is a valid map subscribe for updates
client.subscribe(v.from);
topicsSet[v.from] = v;
Expand Down Expand Up @@ -286,13 +284,22 @@ function mapPacketValue(topic, payload, val) {
return;
}

var options = {
qos: val.qos,
retain: val.retain
// forward the message
if (val.client) {
var options = {
qos: val.qos,
retain: val.retain
}
map.client.publish(topic, payload, options);
} else {
broker.publish({
topic: topic,
qos: val.qos,
retain: val.retain,
payload: payload
});
}

// forward the message
val.client.publish(topic, payload, options);
}

function mapFunction(topic, payload, map) {
Expand Down Expand Up @@ -358,12 +365,20 @@ function mapPacket(topic, payload, map) {
}
}

var options = {
qos: map.qos,
retain: map.retain
if (map.client) {
var options = {
qos: map.qos,
retain: map.retain
}
map.client.publish(topic, payload, options);
} else {
broker.publish({
topic: topic,
qos: map.qos,
retain: map.retain,
payload: payload
})
}

map.client.publish(topic, payload, options);
}

function mapPayload(map, payload) {
Expand Down

0 comments on commit 93bd7f8

Please sign in to comment.