mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add notification for loss of connection to server
This commit is contained in:
parent
2ef907632f
commit
0ceee215f3
@ -113,10 +113,16 @@
|
|||||||
|
|
||||||
var sbc = document.getElementById("debug-content");
|
var sbc = document.getElementById("debug-content");
|
||||||
|
|
||||||
|
var errornotification = null;
|
||||||
|
|
||||||
function debugConnect() {
|
function debugConnect() {
|
||||||
//console.log("debug ws connecting");
|
//console.log("debug ws connecting");
|
||||||
var ws = new WebSocket("ws://"+location.hostname+":"+location.port+document.location.pathname+"/debug");
|
var ws = new WebSocket("ws://"+location.hostname+":"+location.port+document.location.pathname+"/debug");
|
||||||
ws.onopen = function() {
|
ws.onopen = function() {
|
||||||
|
if (errornotification) {
|
||||||
|
errornotification.close();
|
||||||
|
errornotification = null;
|
||||||
|
}
|
||||||
//console.log("debug ws connected");
|
//console.log("debug ws connected");
|
||||||
}
|
}
|
||||||
ws.onmessage = function(event) {
|
ws.onmessage = function(event) {
|
||||||
@ -158,7 +164,9 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
ws.onclose = function() {
|
ws.onclose = function() {
|
||||||
//console.log("debug ws closed");
|
if (errornotification == null) {
|
||||||
|
errornotification = RED.notify("<b>Error</b>: Lost connection to server","error",true);
|
||||||
|
}
|
||||||
setTimeout(debugConnect,1000);
|
setTimeout(debugConnect,1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,22 @@
|
|||||||
RED.notify = function() {
|
RED.notify = function() {
|
||||||
var currentNotifications = [];
|
var currentNotifications = [];
|
||||||
var c = 0;
|
var c = 0;
|
||||||
return function(msg,type) {
|
return function(msg,type,fixed) {
|
||||||
while (currentNotifications.length > 4) {
|
if (currentNotifications.length > 4) {
|
||||||
var n = currentNotifications[0];
|
var ll = currentNotifications.length;
|
||||||
window.clearTimeout(n.id);
|
for (var i = 0;ll > 4 && i<currentNotifications.length;i+=1) {
|
||||||
n.slideup();
|
var n = currentNotifications[i];
|
||||||
|
if (!n.fixed) {
|
||||||
|
window.clearTimeout(n.timeoutid);
|
||||||
|
n.close();
|
||||||
|
ll -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var n = document.createElement("div");
|
var n = document.createElement("div");
|
||||||
|
n.id="red-notification-"+c;
|
||||||
n.className = "alert";
|
n.className = "alert";
|
||||||
|
n.fixed = fixed;
|
||||||
if (type) {
|
if (type) {
|
||||||
n.className = "alert alert-"+type;
|
n.className = "alert alert-"+type;
|
||||||
}
|
}
|
||||||
@ -31,18 +39,21 @@ RED.notify = function() {
|
|||||||
n.innerHTML = msg;
|
n.innerHTML = msg;
|
||||||
$("#notifications").append(n);
|
$("#notifications").append(n);
|
||||||
$(n).slideDown(300);
|
$(n).slideDown(300);
|
||||||
var slideup = function() {
|
n.close = function() {
|
||||||
var nn = n;
|
var nn = n;
|
||||||
return function() {
|
return function() {
|
||||||
currentNotifications.shift();
|
currentNotifications.splice(currentNotifications.indexOf(nn),1);
|
||||||
$(nn).slideUp(300, function() {
|
$(nn).slideUp(300, function() {
|
||||||
nn.parentNode.removeChild(nn);
|
nn.parentNode.removeChild(nn);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}();
|
}();
|
||||||
var id = window.setTimeout(slideup,3000);
|
if (!fixed) {
|
||||||
currentNotifications.push({id:id,slideup:slideup,c:c});
|
n.timeoutid = window.setTimeout(n.close,3000);
|
||||||
|
}
|
||||||
|
currentNotifications.push(n);
|
||||||
c+=1;
|
c+=1;
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user