mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add comms module
This commit is contained in:
@@ -91,7 +91,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
var a = function() {
|
||||
(function() {
|
||||
var content = document.createElement("div");
|
||||
content.id = "tab-debug";
|
||||
|
||||
@@ -114,84 +114,56 @@
|
||||
|
||||
var sbc = document.getElementById("debug-content");
|
||||
|
||||
var errornotification = null;
|
||||
|
||||
var messageCount = 0;
|
||||
|
||||
|
||||
function debugConnect() {
|
||||
//console.log("debug ws connecting");
|
||||
var path = location.hostname+":"+location.port+document.location.pathname;
|
||||
path = path+(path.slice(-1) == "/"?"":"/")+"debug/ws";
|
||||
path = "ws"+(document.location.protocol=="https:"?"s":"")+"://"+path;
|
||||
var ws = new WebSocket(path);
|
||||
ws.onopen = function() {
|
||||
if (errornotification) {
|
||||
errornotification.close();
|
||||
errornotification = null;
|
||||
}
|
||||
//console.log("debug ws connected");
|
||||
}
|
||||
ws.onmessage = function(event) {
|
||||
var o = JSON.parse(event.data);
|
||||
if (o.heartbeat) {
|
||||
return;
|
||||
}
|
||||
//console.log(msg);
|
||||
var msg = document.createElement("div");
|
||||
msg.onmouseover = function() {
|
||||
msg.style.borderRightColor = "#999";
|
||||
var n = RED.nodes.node(o.id);
|
||||
if (n) {
|
||||
n.highlighted = true;
|
||||
n.dirty = true;
|
||||
}
|
||||
RED.view.redraw();
|
||||
};
|
||||
msg.onmouseout = function() {
|
||||
msg.style.borderRightColor = "";
|
||||
var n = RED.nodes.node(o.id);
|
||||
if (n) {
|
||||
n.highlighted = false;
|
||||
n.dirty = true;
|
||||
}
|
||||
RED.view.redraw();
|
||||
};
|
||||
msg.onclick = function() {
|
||||
var node = RED.nodes.node(o.id);
|
||||
if (node) {
|
||||
RED.view.showWorkspace(node.z);
|
||||
}
|
||||
|
||||
};
|
||||
var name = (o.name?o.name:o.id).toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
|
||||
var topic = (o.topic||"").toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
|
||||
var payload = (o.msg||"").toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
|
||||
msg.className = 'debug-message'+(o.level?(' debug-message-level-'+o.level):'')
|
||||
msg.innerHTML = '<span class="debug-message-date">'+getTimestamp()+'</span>'+
|
||||
'<span class="debug-message-name">['+name+']</span>'+
|
||||
(o.topic?'<span class="debug-message-topic">'+topic+'</span>':'')+
|
||||
'<span class="debug-message-payload">'+payload+'</span>';
|
||||
var atBottom = (sbc.scrollHeight-messages.offsetHeight-sbc.scrollTop) < 5;
|
||||
messageCount++;
|
||||
$(messages).append(msg);
|
||||
|
||||
if (messageCount > 200) {
|
||||
$("#debug-content .debug-message:first").remove();
|
||||
messageCount--;
|
||||
}
|
||||
if (atBottom) {
|
||||
$(sbc).scrollTop(sbc.scrollHeight);
|
||||
var handleDebugMessage = function(t,o) {
|
||||
var msg = document.createElement("div");
|
||||
msg.onmouseover = function() {
|
||||
msg.style.borderRightColor = "#999";
|
||||
var n = RED.nodes.node(o.id);
|
||||
if (n) {
|
||||
n.highlighted = true;
|
||||
n.dirty = true;
|
||||
}
|
||||
RED.view.redraw();
|
||||
};
|
||||
ws.onclose = function() {
|
||||
if (errornotification == null) {
|
||||
errornotification = RED.notify("<b>Error</b>: Lost connection to server","error",true);
|
||||
msg.onmouseout = function() {
|
||||
msg.style.borderRightColor = "";
|
||||
var n = RED.nodes.node(o.id);
|
||||
if (n) {
|
||||
n.highlighted = false;
|
||||
n.dirty = true;
|
||||
}
|
||||
setTimeout(debugConnect,1000);
|
||||
RED.view.redraw();
|
||||
};
|
||||
msg.onclick = function() {
|
||||
var node = RED.nodes.node(o.id);
|
||||
if (node) {
|
||||
RED.view.showWorkspace(node.z);
|
||||
}
|
||||
|
||||
};
|
||||
var name = (o.name?o.name:o.id).toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
|
||||
var topic = (o.topic||"").toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
|
||||
var payload = (o.msg||"").toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
|
||||
msg.className = 'debug-message'+(o.level?(' debug-message-level-'+o.level):'')
|
||||
msg.innerHTML = '<span class="debug-message-date">'+getTimestamp()+'</span>'+
|
||||
'<span class="debug-message-name">['+name+']</span>'+
|
||||
(o.topic?'<span class="debug-message-topic">'+topic+'</span>':'')+
|
||||
'<span class="debug-message-payload">'+payload+'</span>';
|
||||
var atBottom = (sbc.scrollHeight-messages.offsetHeight-sbc.scrollTop) < 5;
|
||||
messageCount++;
|
||||
$(messages).append(msg);
|
||||
|
||||
if (messageCount > 200) {
|
||||
$("#debug-content .debug-message:first").remove();
|
||||
messageCount--;
|
||||
}
|
||||
}
|
||||
debugConnect();
|
||||
if (atBottom) {
|
||||
$(sbc).scrollTop(sbc.scrollHeight);
|
||||
}
|
||||
};
|
||||
RED.comms.subscribe("debug",handleDebugMessage);
|
||||
|
||||
$("#debug-tab-clear").click(function() {
|
||||
$(".debug-message").remove();
|
||||
@@ -203,7 +175,7 @@
|
||||
RED.view.redraw();
|
||||
});
|
||||
|
||||
}();
|
||||
})();
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
Reference in New Issue
Block a user