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",
|
||||
"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.*",
|
||||
|
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");
|
||||
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);
|
||||
}
|
||||
|
@ -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,11 +124,9 @@ 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() {
|
||||
console.log("CONNECTED");
|
||||
document.getElementById("foot").innerHTML = "<font color='#494'>"+ibmfoot+"</font>";
|
||||
@ -141,10 +136,11 @@ function start() { // Create the websocket
|
||||
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('error', function() {
|
||||
console.log("ERROR");
|
||||
document.getElementById("foot").innerHTML = "<font color='#C00'>"+ibmfoot+"</font>";
|
||||
});
|
||||
|
||||
ws.on('worldmapdata', function(data) {
|
||||
@ -153,12 +149,6 @@ function start() { // Create the websocket
|
||||
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"));
|
||||
|
Loading…
Reference in New Issue
Block a user