aboutsummaryrefslogtreecommitdiff
path: root/juick-ws
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-07-25 23:07:56 +0300
committerGravatar Vitaly Takmazov2016-07-27 13:57:04 +0300
commit8c09444ea4664d41002ec6df6574ed696bfb2935 (patch)
tree30f63c8e2445b6b21a69d71d53eb63234a80bc0a /juick-ws
parenta18f5e5012b862992af40db60c83a40098342b53 (diff)
terminal: fix status and keepalive refresh
Diffstat (limited to 'juick-ws')
-rw-r--r--juick-ws/src/main/static/scripts.js32
1 files changed, 21 insertions, 11 deletions
diff --git a/juick-ws/src/main/static/scripts.js b/juick-ws/src/main/static/scripts.js
index 9b4c721f..1a212563 100644
--- a/juick-ws/src/main/static/scripts.js
+++ b/juick-ws/src/main/static/scripts.js
@@ -9,6 +9,25 @@ function ready(fn) {
}
}
+function refreshStatus() {
+ setTimeout(function() {
+ fetch("/api/status")
+ .then(function(response) {
+ return response.text();
+ }).then(function(body) {
+ status.textContent = JSON.parse(body).status;
+ refreshStatus();
+ })
+ }, 5000);
+}
+
+function keepalive() {
+ setTimeout(function() {
+ ws.send(" ");
+ keepalive();
+ }, 60000);
+}
+
ready(function() {
var ws = new WebSocket('wss://ws.juick.com/');
var term = new Terminal('terminal', {}, {});
@@ -22,15 +41,6 @@ ready(function() {
ws.onmessage = function(msg) {
term.output("<br/>" + JSON.stringify(JSON.parse(msg.data), null, 2));
}
- setTimeout(function() {
- ws.send(" ");
- }, 60000);
- setTimeout(function() {
- fetch("/api/status")
- .then(function(response) {
- return response.text();
- }).then(function(body) {
- status.textContent = JSON.parse(body).status;
- })
- }, 5000);
+ refreshStatus();
+ keepalive();
}) \ No newline at end of file