blob: c8c773bc1cd6495d413b26c8d1c84c69a452602c (
plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Moniteur de Glutte</title>
<link rel="stylesheet" href="static/style.css" type="text/css" media="screen" charset="utf-8"/>
</head>
<body>
<h1>Ceci n'est pas une Glutte</h1>
<pre id="output">{% for l in last_lines %}{{l}}{% endfor %}</pre>
<script>
var output = document.getElementById('output');
var socket = null;
var closed = true;
var retry_scheduled = false;
function init_socket() {
retry_scheduled = false;
if (socket != null) {
socket.onmessage = null;
socket.onopen = null;
socket.onclose = null;
socket.onerror = null;
delete socket;
}
socket = new WebSocket("ws://" + window.location.host + "/stream");
socket.onmessage = function(data) {
output.textContent += data.data;
window.scrollTo(0, document.body.scrollHeight);
}
socket.onopen = function(data) {
output.textContent += "{System} Websocket open !\n";
window.scrollTo(0, document.body.scrollHeight);
closed = false;
}
socket.onclose = function(code, text) {
closed = true;
if (!retry_scheduled) {
output.textContent += "{System} Websocket closed :( " + text + "\n";
window.scrollTo(0, document.body.scrollHeight);
retry_scheduled = true;
init_socket();
}
}
socket.onerror = function() {
closed = true;
if (!retry_scheduled) {
output.textContent += "{System} Websocket error. Trying again in 3s :(\n";
window.scrollTo(0, document.body.scrollHeight);
setTimeout(init_socket, 3000);
retry_scheduled = true;
}
}
}
function keep_alive() {
if (!closed) {
try {
socket.send('.');
} catch (e) {
}
}
setTimeout(keep_alive, 10000);
}
init_socket();
keep_alive();
</script>
</body>
</html>
|