diff --git a/README.md b/README.md index afa2375..4dca6a1 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ To add a new base layer msg.payload.command.map = { name:"OSMhot", url:'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', - opt:JSON.stringify('{ maxZoom: 19, attribution: "© OpenStreetMap"}') + opt:{ maxZoom:19, attribution:"© OpenStreetMap" } }; Demo Flow diff --git a/package.json b/package.json index bbcabd7..ac4f5eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "node-red-contrib-web-worldmap", - "version" : "1.0.7", + "version" : "1.0.8", "description" : "A Node-RED node to provide a web page of a world map for plotting things on.", "dependencies" : { "express": "4.*", diff --git a/worldmap.js b/worldmap.js index ae6a53b..88632f3 100644 --- a/worldmap.js +++ b/worldmap.js @@ -24,8 +24,7 @@ module.exports = function(RED) { var node = this; //node.log("Serving map from "+__dirname+" as "+RED.settings.httpNodeRoot.slice(0,-1)+"/worldmap"); RED.httpNode.use("/worldmap", express.static(__dirname + '/worldmap')); - io.on('connection', function(socket) { - //node.log(socket.request.connection.remoteAddress); + var callback = function(socket) { node.status({fill:"green",shape:"dot",text:"connected"}); node.on('input', function(msg) { socket.emit("worldmapdata",msg.payload); @@ -33,18 +32,20 @@ module.exports = function(RED) { socket.on('disconnect', function() { node.status({fill:"red",shape:"ring",text:"disconnected"}); }); - }); - node.on("close", function() { - node.status({}); - }); - + node.on("close", function() { + node.status({}); + socket.disconnect(); + io.sockets.removeListener('connection', callback); + }); + } + io.on('connection', callback ); } RED.nodes.registerType("worldmap",WorldMap); var WorldMapIn = function(n) { RED.nodes.createNode(this,n); var node = this; - io.on('connection', function(socket) { + var callback = function(socket) { node.status({fill:"green",shape:"dot",text:"connected"}); socket.on('worldmap', function(data) { node.send({payload:data, topic:"worldmap"}); @@ -53,10 +54,13 @@ module.exports = function(RED) { node.status({fill:"red",shape:"ring",text:"disconnected"}); node.send({payload:{action:"disconnect"}, topic:"worldmap"}); }); - }); - node.on("close", function() { - node.status({}); - }); + node.on("close", function() { + node.status({}); + socket.disconnect(); + io.sockets.removeListener('connection', callback); + }); + } + io.on('connection', callback); } RED.nodes.registerType("worldmap in",WorldMapIn); } diff --git a/worldmap/index.html b/worldmap/index.html index 4aaac4f..07229cc 100644 --- a/worldmap/index.html +++ b/worldmap/index.html @@ -63,7 +63,7 @@