/
index.html
56 lines (55 loc) · 1.6 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head lang='en'>
<meta charset='utf-8'>
<title>Line Chunker Client Test</title>
<style type='text/css'>
html {
overflow-y: scroll;
scroll-behavior: smooth;
}
</style>
</head>
<body>
<pre id='lines'>
(Waiting...)
</pre>
<script type='text/javascript'>
const conn = new WebSocket('ws://127.0.0.1:8080');
let cnt = 0;
let lines = 0;
const root = document.documentElement;
let oldTop = root.scrollTop;
const pre = document.getElementById('lines');
const tserr = (e) => console.log('Error sending timespan', e);
conn.onopen = () => {
console.log('opened connection');
conn.send('timespan 5000', tserr);
};
conn.onerror = (e) => {
const s = `Error opening websocket ${e.target.url}`;
pre.textContent = s;
console.log(s);
}
conn.onmessage = (msg) => {
if (cnt === 0) {
pre.textContent = '';
}
pre.textContent = pre.textContent.concat(msg.data);
let chunk = msg.data.split(/^/m);
let lt = chunk[chunk.length-1].split(' ')[0];
console.log('msg of %d bytes, %d lines (%d so far) last time %s',
msg.data.length, chunk.length, lines += chunk.length, lt);
if(++cnt === 2) {
conn.send('timespan 1000', tserr);
console.log('changed timespan');
}
// if at bottom of window, autoscroll it
if (root.scrollTop >= oldTop) {
root.scrollTop = pre.scrollHeight + 8;
oldTop = root.scrollTop;
}
};
</script>
</body>
</html>