aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src/main/static
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-07-25 21:36:50 +0300
committerGravatar Vitaly Takmazov2016-07-27 13:56:09 +0300
commit69af3f60d399157a8951988fa2f91d29c553fbb5 (patch)
tree8c38def00d1b3dc5e38cf421870afb62f3a823ea /juick-ws/src/main/static
parent94c0d43d2765488d715bffe426934ed7caa8f4f2 (diff)
juick-ws: websocket terminal
Diffstat (limited to 'juick-ws/src/main/static')
-rw-r--r--juick-ws/src/main/static/scripts.js36
-rw-r--r--juick-ws/src/main/static/style.css2
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