-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowsersource.js
56 lines (46 loc) · 1.4 KB
/
browsersource.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
46
47
48
49
50
51
52
53
54
55
56
function getCells(data, type) {
cells="";
for (const property in data) {
cells += `<${type}>${data[property]}</${type}>`;
}
return cells;
}
function createBody(data) {
return data.map(row => `<tr>${getCells(row, 'td')}</tr>`).join('');
}
function createTable(data) {
// Destructure the headings (first row) from
// all the rows
const [headings, ...rows] = data;
// Return some HTML that uses `getCells` to create
// some headings, but also to create the rows
// in the tbody.
return `
<thead>${getCells(headings, 'th')}</thead>
<tbody>${createBody(rows)}</tbody>
`;
}
function fillTable(data) {
if (Array.isArray(data)) {
data.unshift({"number": "number", "name": "name"});
let tablerender = createTable(data);
document.getElementById("entries").innerHTML = tablerender;
console.log("it works?");
}
}
// const socket = new WebSocket("ws://localhost:5678");
const socket = new WebSocket("ws://216.164.205.34:64209");
function refresh_queue() {
socket.send("send_queue");
}
// Send a message to the server to trigger the queue send
socket.onopen = function() {
refresh_queue();
window.setInterval(refresh_queue, 2000);
};
// Receive the queue from the server
socket.onmessage = function(event) {
jsondata = JSON.parse(event.data);
console.log(jsondata);
fillTable(jsondata);
};