aboutsummaryrefslogtreecommitdiffstats
path: root/templates
diff options
context:
space:
mode:
authorMaximilien Cuony <maximilien@theglu.org>2016-09-12 17:42:38 +0200
committerMaximilien Cuony <maximilien@theglu.org>2016-09-12 17:42:38 +0200
commit259bef01537a56ee6d484d0b6958a350af3045eb (patch)
treebf83d721bf974e4e40296b9531dfe0d59adf2f15 /templates
parent0a0f764dc55d4e3e9b19a40cfa5ae8dbaf70e51d (diff)
downloadglutte-serial-web-259bef01537a56ee6d484d0b6958a350af3045eb.tar.gz
glutte-serial-web-259bef01537a56ee6d484d0b6958a350af3045eb.tar.bz2
glutte-serial-web-259bef01537a56ee6d484d0b6958a350af3045eb.zip
Add a pause button
Diffstat (limited to 'templates')
-rw-r--r--templates/index.html36
1 files changed, 27 insertions, 9 deletions
diff --git a/templates/index.html b/templates/index.html
index c8c773b..9687b25 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -6,14 +6,16 @@
<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>
+ <h1>Ceci n'est pas une Glutte <input type="checkbox" id="pause"><small><small>Pause</small></small></h1>
<pre id="output">{% for l in last_lines %}{{l}}{% endfor %}</pre>
<script>
var output = document.getElementById('output');
+ var pause = document.getElementById('pause');
var socket = null;
var closed = true;
var retry_scheduled = false;
+ var pause_buffer = '';
function init_socket() {
@@ -32,21 +34,18 @@
socket = new WebSocket("ws://" + window.location.host + "/stream");
socket.onmessage = function(data) {
- output.textContent += data.data;
- window.scrollTo(0, document.body.scrollHeight);
+ add_message(data.data);
}
socket.onopen = function(data) {
- output.textContent += "{System} Websocket open !\n";
- window.scrollTo(0, document.body.scrollHeight);
+ add_message("{System} Websocket open !\n");
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);
+ add_message("{System} Websocket closed :( " + text + "\n");
retry_scheduled = true;
init_socket();
}
@@ -56,8 +55,7 @@
closed = true;
if (!retry_scheduled) {
- output.textContent += "{System} Websocket error. Trying again in 3s :(\n";
- window.scrollTo(0, document.body.scrollHeight);
+ add_message("{System} Websocket error. Trying again in 3s :(\n");
setTimeout(init_socket, 3000);
retry_scheduled = true;
}
@@ -77,6 +75,26 @@
setTimeout(keep_alive, 10000);
}
+ function add_message(text) {
+ if (pause.checked) {
+ pause_buffer += text;
+ } else {
+ output.textContent += text;
+ window.scrollTo(0, document.body.scrollHeight);
+ }
+ }
+
+ function pause_changed() {
+ if (!pause.checked) {
+ if (pause_buffer) {
+ add_message(pause_buffer);
+ pause_buffer = "";
+ }
+ }
+ }
+
+ pause.onchange = pause_changed;
+
init_socket();
keep_alive();
</script>