Add status to world map node

This commit is contained in:
Dave Conway-Jones 2016-05-24 21:34:18 +01:00
parent 8629f1f017
commit 786cee3ed9
3 changed files with 35 additions and 32 deletions

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-contrib-web-worldmap",
"version" : "1.0.1",
"version" : "1.0.2",
"description" : "A Node-RED node to provide a web page of a world map for plotting things on.",
"dependencies" : {
"express": "4.*",

View File

@ -25,9 +25,17 @@ module.exports = function(RED) {
//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);
node.status({fill:"green",shape:"dot",text:"connected"});
node.on('input', function(msg) {
socket.emit("worldmapdata",msg.payload);
});
socket.on('disconnect', function() {
node.status({fill:"red",shape:"ring",text:"disconnected"});
});
});
node.on("close", function() {
node.status({});
});
}
RED.nodes.registerType("worldmap",WorldMap);
@ -36,13 +44,18 @@ module.exports = function(RED) {
RED.nodes.createNode(this,n);
var node = this;
io.on('connection', function(socket) {
node.status({fill:"green",shape:"dot",text:"connected"});
socket.on('worldmap', function(data) {
node.send({payload:data, topic:"worldmap"});
});
socket.on('disconnect', function() {
node.status({fill:"red",shape:"ring",text:"disconnected"});
node.send({payload:{action:"disconnect"}, topic:"worldmap"});
});
});
node.on("close", function() {
node.status({});
});
}
RED.nodes.registerType("worldmap in",WorldMapIn);
}

View File

@ -114,9 +114,6 @@ var menuOpen = false;
var clusterAt = 1;
var maxage = 600; // default max age of icons on map in seconds - cleared after 10 mins
var baselayername = "OSM grey"; // Default base layer OSM but uniform grey
var ws;
var wsUri;
var loc = window.location;
window.onbeforeunload = function(e) {
return 'Reloading will delete all the local markers, including any drawing on the "drawing" layer';
@ -127,38 +124,31 @@ else { console.log("NOT in an Iframe"); }
var ibmfoot = " © IBM 2015,2016"
function start() { // Create the websocket
//ws = new WebSocket(wsUri);
ws = io();
// Create the socket
var ws = io();
//ws.onopen = function(evt) {
ws.on('connect', function() {
ws.on('connect', function() {
console.log("CONNECTED");
document.getElementById("foot").innerHTML = "<font color='#494'>"+ibmfoot+"</font>";
ws.emit("worldmap",{action:"connected"});
});
});
ws.on('disconnect', function() {
ws.on('disconnect', function() {
console.log("DISCONNECTED");
document.getElementById("foot").innerHTML = "<font color='#900'>"+ibmfoot+"</font>";
socketConnectTimeInterval = setInterval(function () {
ws.socket.reconnect();
if (ws.socket.connected) { clearInterval(socketConnectTimeInterval); }
}, 3000);
});
});
ws.on('worldmapdata', function(data) {
ws.on('error', function() {
console.log("ERROR");
document.getElementById("foot").innerHTML = "<font color='#C00'>"+ibmfoot+"</font>";
});
ws.on('worldmapdata', function(data) {
if (data.command) { doCommand(data.command); delete data.command; }
if (data.hasOwnProperty("name") && data.hasOwnProperty("lat") && data.hasOwnProperty("lon")) { setMarker(data); }
else { console.log("SKIP",data); }
});
});
ws.on('error', function(evt) {
console.log("ERROR",evt);
document.getElementById("foot").innerHTML = "<font color='#f00'>"+ibmfoot+"</font>";
});
}
start();
if ( window.localStorage.hasOwnProperty("lastpos") ) {
var sp = JSON.parse(window.localStorage.getItem("lastpos"));