|
91 | 91 | } |
92 | 92 | }); |
93 | 93 |
|
94 | | - var a = function() { |
| 94 | + (function() { |
95 | 95 | var content = document.createElement("div"); |
96 | 96 | content.id = "tab-debug"; |
97 | 97 |
|
|
114 | 114 |
|
115 | 115 | var sbc = document.getElementById("debug-content"); |
116 | 116 |
|
117 | | - var errornotification = null; |
118 | | - |
119 | 117 | var messageCount = 0; |
120 | 118 |
|
121 | | - |
122 | | - function debugConnect() { |
123 | | - //console.log("debug ws connecting"); |
124 | | - var path = location.hostname+":"+location.port+document.location.pathname; |
125 | | - path = path+(path.slice(-1) == "/"?"":"/")+"debug/ws"; |
126 | | - path = "ws"+(document.location.protocol=="https:"?"s":"")+"://"+path; |
127 | | - var ws = new WebSocket(path); |
128 | | - ws.onopen = function() { |
129 | | - if (errornotification) { |
130 | | - errornotification.close(); |
131 | | - errornotification = null; |
132 | | - } |
133 | | - //console.log("debug ws connected"); |
134 | | - } |
135 | | - ws.onmessage = function(event) { |
136 | | - var o = JSON.parse(event.data); |
137 | | - if (o.heartbeat) { |
138 | | - return; |
| 119 | + var handleDebugMessage = function(t,o) { |
| 120 | + var msg = document.createElement("div"); |
| 121 | + msg.onmouseover = function() { |
| 122 | + msg.style.borderRightColor = "#999"; |
| 123 | + var n = RED.nodes.node(o.id); |
| 124 | + if (n) { |
| 125 | + n.highlighted = true; |
| 126 | + n.dirty = true; |
139 | 127 | } |
140 | | - //console.log(msg); |
141 | | - var msg = document.createElement("div"); |
142 | | - msg.onmouseover = function() { |
143 | | - msg.style.borderRightColor = "#999"; |
144 | | - var n = RED.nodes.node(o.id); |
145 | | - if (n) { |
146 | | - n.highlighted = true; |
147 | | - n.dirty = true; |
148 | | - } |
149 | | - RED.view.redraw(); |
150 | | - }; |
151 | | - msg.onmouseout = function() { |
152 | | - msg.style.borderRightColor = ""; |
153 | | - var n = RED.nodes.node(o.id); |
154 | | - if (n) { |
155 | | - n.highlighted = false; |
156 | | - n.dirty = true; |
157 | | - } |
158 | | - RED.view.redraw(); |
159 | | - }; |
160 | | - msg.onclick = function() { |
161 | | - var node = RED.nodes.node(o.id); |
162 | | - if (node) { |
163 | | - RED.view.showWorkspace(node.z); |
164 | | - } |
165 | | - |
166 | | - }; |
167 | | - var name = (o.name?o.name:o.id).toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"); |
168 | | - var topic = (o.topic||"").toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"); |
169 | | - var payload = (o.msg||"").toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"); |
170 | | - msg.className = 'debug-message'+(o.level?(' debug-message-level-'+o.level):'') |
171 | | - msg.innerHTML = '<span class="debug-message-date">'+getTimestamp()+'</span>'+ |
172 | | - '<span class="debug-message-name">['+name+']</span>'+ |
173 | | - (o.topic?'<span class="debug-message-topic">'+topic+'</span>':'')+ |
174 | | - '<span class="debug-message-payload">'+payload+'</span>'; |
175 | | - var atBottom = (sbc.scrollHeight-messages.offsetHeight-sbc.scrollTop) < 5; |
176 | | - messageCount++; |
177 | | - $(messages).append(msg); |
178 | | - |
179 | | - if (messageCount > 200) { |
180 | | - $("#debug-content .debug-message:first").remove(); |
181 | | - messageCount--; |
182 | | - } |
183 | | - if (atBottom) { |
184 | | - $(sbc).scrollTop(sbc.scrollHeight); |
| 128 | + RED.view.redraw(); |
| 129 | + }; |
| 130 | + msg.onmouseout = function() { |
| 131 | + msg.style.borderRightColor = ""; |
| 132 | + var n = RED.nodes.node(o.id); |
| 133 | + if (n) { |
| 134 | + n.highlighted = false; |
| 135 | + n.dirty = true; |
185 | 136 | } |
| 137 | + RED.view.redraw(); |
186 | 138 | }; |
187 | | - ws.onclose = function() { |
188 | | - if (errornotification == null) { |
189 | | - errornotification = RED.notify("<b>Error</b>: Lost connection to server","error",true); |
| 139 | + msg.onclick = function() { |
| 140 | + var node = RED.nodes.node(o.id); |
| 141 | + if (node) { |
| 142 | + RED.view.showWorkspace(node.z); |
190 | 143 | } |
191 | | - setTimeout(debugConnect,1000); |
| 144 | + |
| 145 | + }; |
| 146 | + var name = (o.name?o.name:o.id).toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"); |
| 147 | + var topic = (o.topic||"").toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"); |
| 148 | + var payload = (o.msg||"").toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"); |
| 149 | + msg.className = 'debug-message'+(o.level?(' debug-message-level-'+o.level):'') |
| 150 | + msg.innerHTML = '<span class="debug-message-date">'+getTimestamp()+'</span>'+ |
| 151 | + '<span class="debug-message-name">['+name+']</span>'+ |
| 152 | + (o.topic?'<span class="debug-message-topic">'+topic+'</span>':'')+ |
| 153 | + '<span class="debug-message-payload">'+payload+'</span>'; |
| 154 | + var atBottom = (sbc.scrollHeight-messages.offsetHeight-sbc.scrollTop) < 5; |
| 155 | + messageCount++; |
| 156 | + $(messages).append(msg); |
| 157 | + |
| 158 | + if (messageCount > 200) { |
| 159 | + $("#debug-content .debug-message:first").remove(); |
| 160 | + messageCount--; |
192 | 161 | } |
193 | | - } |
194 | | - debugConnect(); |
| 162 | + if (atBottom) { |
| 163 | + $(sbc).scrollTop(sbc.scrollHeight); |
| 164 | + } |
| 165 | + }; |
| 166 | + RED.comms.subscribe("debug",handleDebugMessage); |
195 | 167 |
|
196 | 168 | $("#debug-tab-clear").click(function() { |
197 | 169 | $(".debug-message").remove(); |
|
203 | 175 | RED.view.redraw(); |
204 | 176 | }); |
205 | 177 |
|
206 | | - }(); |
| 178 | + })(); |
207 | 179 | </script> |
208 | 180 |
|
209 | 181 | <style> |
|
0 commit comments