From 8c09444ea4664d41002ec6df6574ed696bfb2935 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 25 Jul 2016 23:07:56 +0300 Subject: terminal: fix status and keepalive refresh --- juick-ws/src/main/static/scripts.js | 32 +++++++++++++++++++++----------- 1 file 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("
" + 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 -- cgit v1.2.3