-
Notifications
You must be signed in to change notification settings - Fork 6
/
browser.main.js
45 lines (40 loc) · 1.36 KB
/
browser.main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// https://websocket.org/echo.html
let websocket = new WebSocket("ws://localhost:8080")
let metricOutput = document.getElementById("metric");
let logOutput = document.getElementById("log");
let logs = [];
let writeLog = (msg, topic = "common") => {
return ;
let d = new Date();
if (typeof msg !== 'string') {
msg = JSON.stringify(msg);
}
let txt = `${d.toLocaleTimeString()} [${topic}] ${msg}\r\n${logOutput.innerText}`;
logs.unshift(txt);
//logs = logs.slice(0, Math.min(10, logs.length));
logOutput.innerText = logs.join("\r\n");
}
let client1 = null;
websocket.onopen = function (evt) {
document.getElementById('online-badge').style.display = 'inline';
document.getElementById('offline-badge').style.display = 'none';
updateOpcNodeListener();
};
websocket.onclose = () => {
document.getElementById('online-badge').style.display = 'none';
document.getElementById('offline-badge').style.display = 'inline';
}
websocket.onmessage = msg => {
metricOutput.innerText = msg.data;
writeLog(msg.data, "onmessage");
}
websocket.onerror = console.error;
function updateOpcNodeListener() {
let config = document.getElementById("nodeIds").value;
config = config.replace(/\r/g, "");
config = config.split("\n");
writeLog(config, "config update");
websocket.send(JSON.stringify({
nodes: config
}));
}