Skip to content

Commit

Permalink
Implment Message API
Browse files Browse the repository at this point in the history
  • Loading branch information
hardillb committed Nov 4, 2020
1 parent 41a0dda commit 77870a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 25 additions & 4 deletions geofence.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ module.exports = function(RED) {
this.inside = n.inside;
var node = this;

node.on('input', function(msg) {
node.on('input', function(msg, send, done) {
var loc = undefined;

send = send || function() { node.send.apply(node,arguments) }

if (msg.hasOwnProperty('location') && msg.location.hasOwnProperty('lat') && msg.location.hasOwnProperty('lon')) {
loc = {
latitude: msg.location.lat,
Expand Down Expand Up @@ -65,11 +67,19 @@ module.exports = function(RED) {
msg.location.isat = msg.location.isat || [];
msg.location.isat.push(node.name);
}
node.send(msg);
send(msg);
if (done) {
done();
}
return
}

if (!inout && (node.inside === "false")) {
node.send(msg);
send(msg);
if (done) {
done();
}
return;
}

if (node.inside === "both") {
Expand Down Expand Up @@ -104,7 +114,18 @@ module.exports = function(RED) {
msg.location.distances = msg.location.distances || {};
msg.location.distances[node.name] = distance;
}
node.send(msg);
send(msg);
if (done) {
done();
}
return;
}
} else {
//no location
if (done) {
done("No location found in message")
} else {
node.error("No location found in message", msg);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-node-geofence",
"version": "0.1.3",
"version": "0.1.4",
"description": "A simple node to filter based on location",
"dependencies" :{
"geolib": "^2.0.0"
Expand Down

0 comments on commit 77870a7

Please sign in to comment.