Add status to world map node
This commit is contained in:
parent
8629f1f017
commit
786cee3ed9
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-contrib-web-worldmap",
|
"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.",
|
"description" : "A Node-RED node to provide a web page of a world map for plotting things on.",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"express": "4.*",
|
"express": "4.*",
|
||||||
|
13
worldmap.js
13
worldmap.js
@ -25,9 +25,17 @@ module.exports = function(RED) {
|
|||||||
//node.log("Serving map from "+__dirname+" as "+RED.settings.httpNodeRoot.slice(0,-1)+"/worldmap");
|
//node.log("Serving map from "+__dirname+" as "+RED.settings.httpNodeRoot.slice(0,-1)+"/worldmap");
|
||||||
RED.httpNode.use("/worldmap", express.static(__dirname + '/worldmap'));
|
RED.httpNode.use("/worldmap", express.static(__dirname + '/worldmap'));
|
||||||
io.on('connection', function(socket) {
|
io.on('connection', function(socket) {
|
||||||
|
node.log(socket.request.connection.remoteAddress);
|
||||||
|
node.status({fill:"green",shape:"dot",text:"connected"});
|
||||||
node.on('input', function(msg) {
|
node.on('input', function(msg) {
|
||||||
socket.emit("worldmapdata",msg.payload);
|
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);
|
RED.nodes.registerType("worldmap",WorldMap);
|
||||||
@ -36,13 +44,18 @@ module.exports = function(RED) {
|
|||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
var node = this;
|
var node = this;
|
||||||
io.on('connection', function(socket) {
|
io.on('connection', function(socket) {
|
||||||
|
node.status({fill:"green",shape:"dot",text:"connected"});
|
||||||
socket.on('worldmap', function(data) {
|
socket.on('worldmap', function(data) {
|
||||||
node.send({payload:data, topic:"worldmap"});
|
node.send({payload:data, topic:"worldmap"});
|
||||||
});
|
});
|
||||||
socket.on('disconnect', function() {
|
socket.on('disconnect', function() {
|
||||||
|
node.status({fill:"red",shape:"ring",text:"disconnected"});
|
||||||
node.send({payload:{action:"disconnect"}, topic:"worldmap"});
|
node.send({payload:{action:"disconnect"}, topic:"worldmap"});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
node.on("close", function() {
|
||||||
|
node.status({});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("worldmap in",WorldMapIn);
|
RED.nodes.registerType("worldmap in",WorldMapIn);
|
||||||
}
|
}
|
||||||
|
@ -114,9 +114,6 @@ var menuOpen = false;
|
|||||||
var clusterAt = 1;
|
var clusterAt = 1;
|
||||||
var maxage = 600; // default max age of icons on map in seconds - cleared after 10 mins
|
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 baselayername = "OSM grey"; // Default base layer OSM but uniform grey
|
||||||
var ws;
|
|
||||||
var wsUri;
|
|
||||||
var loc = window.location;
|
|
||||||
|
|
||||||
window.onbeforeunload = function(e) {
|
window.onbeforeunload = function(e) {
|
||||||
return 'Reloading will delete all the local markers, including any drawing on the "drawing" layer';
|
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"
|
var ibmfoot = " © IBM 2015,2016"
|
||||||
|
|
||||||
function start() { // Create the websocket
|
// Create the socket
|
||||||
//ws = new WebSocket(wsUri);
|
var ws = io();
|
||||||
ws = io();
|
|
||||||
|
|
||||||
//ws.onopen = function(evt) {
|
ws.on('connect', function() {
|
||||||
ws.on('connect', function() {
|
console.log("CONNECTED");
|
||||||
console.log("CONNECTED");
|
document.getElementById("foot").innerHTML = "<font color='#494'>"+ibmfoot+"</font>";
|
||||||
document.getElementById("foot").innerHTML = "<font color='#494'>"+ibmfoot+"</font>";
|
ws.emit("worldmap",{action:"connected"});
|
||||||
ws.emit("worldmap",{action:"connected"});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
ws.on('disconnect', function() {
|
ws.on('disconnect', function() {
|
||||||
console.log("DISCONNECTED");
|
console.log("DISCONNECTED");
|
||||||
document.getElementById("foot").innerHTML = "<font color='#900'>"+ibmfoot+"</font>";
|
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() {
|
||||||
if (data.command) { doCommand(data.command); delete data.command; }
|
console.log("ERROR");
|
||||||
if (data.hasOwnProperty("name") && data.hasOwnProperty("lat") && data.hasOwnProperty("lon")) { setMarker(data); }
|
document.getElementById("foot").innerHTML = "<font color='#C00'>"+ibmfoot+"</font>";
|
||||||
else { console.log("SKIP",data); }
|
});
|
||||||
});
|
|
||||||
|
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") ) {
|
if ( window.localStorage.hasOwnProperty("lastpos") ) {
|
||||||
var sp = JSON.parse(window.localStorage.getItem("lastpos"));
|
var sp = JSON.parse(window.localStorage.getItem("lastpos"));
|
||||||
|
Loading…
Reference in New Issue
Block a user