From aff51c116a1c0f05660bc0f3eda4e412eae90fda Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Mon, 2 Sep 2019 15:08:34 +0100 Subject: [PATCH] let worldap in node only send connect events if required. (makes life easier for resends etc..) Bump package etc in anticipation of release etc. --- CHANGELOG.md | 3 ++- README.md | 5 ++--- package.json | 2 +- worldmap.html | 10 +++++++++- worldmap.js | 13 +++++++++++-- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e3046a..c588905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ ### Change Log for Node-RED Worldmap + - v2.1.0 - Add ui-worldmap node to make embedding in Dashboard easier. Let in node specify connection actions only. - v2.0.22 - fix SIDC missing property - - v2.0.21 - allow adding overlays without making them visible (visible:false) - Issue #108 + - v2.0.21 - allow adding overlays without making them visible (visible:false). Issue #108 - v2.0.20 - ensure `fit` option is boolean, Issue #109. Fix track layers, Issue #110. - v2.0.18 - Stop map contextmenu bleedthrough to marker. Add compress middleware. - v2.0.17 - Let clear command also clear tracks from tracks node diff --git a/README.md b/README.md index af38182..d97d15b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # node-red-contrib-web-worldmap -![NPM version](https://badge.fury.io/js/node-red-contrib-web-worldmap.svg) - A Node-RED node to provide a world map web page for plotting "things" on. @@ -9,8 +7,9 @@ map web page for plotting "things" on. ### Updates +- v2.1.0 - Add ui-worldmap node to make embedding in Dashboard easier. - v2.0.22 - fix SIDC missing property -- v2.0.21 - allow adding overlays without making them visible (visible:false) - Issue #108 +- v2.0.21 - allow adding overlays without making them visible (visible:false). Issue #108 - v2.0.20 - ensure `fit` option is boolean, Issue #109. Fix track layers, Issue #110. - v2.0.18 - Stop map contextmenu bleedthrough to marker. Add compress middleware. - v2.0.17 - Let clear command also clear tracks from tracks node diff --git a/package.json b/package.json index a69ed11..917d294 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-web-worldmap", - "version": "2.0.22", + "version": "2.1.0", "description": "A Node-RED node to provide a web page of a world map for plotting things on.", "dependencies": { "cgi": "0.3.1", diff --git a/worldmap.html b/worldmap.html index 3f007ae..d6a752c 100644 --- a/worldmap.html +++ b/worldmap.html @@ -437,6 +437,13 @@ then by default ⌘⇧m - ctrl-shift-m will load the m +
+ + +
@@ -472,7 +479,8 @@ then by default ⌘⇧m - ctrl-shift-m will load the m color:"darksalmon", defaults: { name: {value:""}, - path: {value:"/worldmap"} + path: {value:"/worldmap"}, + events: {value:"all"} }, inputs:0, outputs:1, diff --git a/worldmap.js b/worldmap.js index 77c9a6e..23030f2 100644 --- a/worldmap.js +++ b/worldmap.js @@ -202,6 +202,7 @@ module.exports = function(RED) { var WorldMapIn = function(n) { RED.nodes.createNode(this,n); this.path = n.path || "/worldmap"; + this.events = n.events || "all"; if (this.path.charAt(0) != "/") { this.path = "/" + this.path; } if (!sockets[this.path]) { var libPath = path.posix.join(RED.settings.httpNodeRoot, this.path, 'leaflet', 'sockjs.min.js'); @@ -218,12 +219,20 @@ module.exports = function(RED) { node.status({fill:"green",shape:"dot",text:"connected "+Object.keys(clients).length,_sessionid:client.id}); client.on('data', function(message) { message = JSON.parse(message); - setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id})}); + console.log("GOT:",message); + if ((node.events === "connect") && message.hasOwnProperty("action") && (message.action === "connected")) { + setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id})}); + } else { + setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id})}); + } }); client.on('close', function() { delete clients[client.id]; node.status({fill:"green",shape:"ring",text:"connected "+Object.keys(clients).length,_sessionid:client.id}); - node.send({payload:{action:"disconnect", clients:Object.keys(clients).length}, topic:node.path.substr(1), _sessionid:client.id}); + console.log("BYE:",node.events); + if (node.events !== "connect") { + node.send({payload:{action:"disconnect", clients:Object.keys(clients).length}, topic:node.path.substr(1), _sessionid:client.id}); + } }); }