diff options
Diffstat (limited to 'juick-ws/src/main/static')
-rw-r--r-- | juick-ws/src/main/static/scripts.js | 36 | ||||
-rw-r--r-- | juick-ws/src/main/static/style.css | 2 |
2 files changed, 38 insertions, 0 deletions
diff --git a/juick-ws/src/main/static/scripts.js b/juick-ws/src/main/static/scripts.js new file mode 100644 index 00000000..2691816d --- /dev/null +++ b/juick-ws/src/main/static/scripts.js @@ -0,0 +1,36 @@ +var Terminal = require('terminal'); +require('whatwg-fetch'); + +function ready(fn) { + if (document.readyState != 'loading') { + fn(); + } else { + document.addEventListener('DOMContentLoaded', fn); + } +} + +ready(function() { + var ws = new WebSocket('wss://ws.juick.com/_replies'); + var term = new Terminal('terminal', {}, {}); + var status = document.querySelector("#status"); + ws.onopen = function() { + term.output("<br/>connected"); + }; + ws.onclose = function() { + term.output("<br/>disconnected"); + } + 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).clientsCount; + }) + }, 5000); +})
\ No newline at end of file diff --git a/juick-ws/src/main/static/style.css b/juick-ws/src/main/static/style.css new file mode 100644 index 00000000..ee5ec6b7 --- /dev/null +++ b/juick-ws/src/main/static/style.css @@ -0,0 +1,2 @@ +@import "normalize.css"; +@import "terminal";
\ No newline at end of file |