aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src/main/static/scripts.js
diff options
context:
space:
mode:
Diffstat (limited to 'juick-ws/src/main/static/scripts.js')
-rw-r--r--juick-ws/src/main/static/scripts.js36
1 files changed, 36 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