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/');
var term = new Terminal('terminal', {}, {});
var status = document.querySelector("#status");
ws.onopen = function() {
term.output("
connected");
};
ws.onclose = function() {
term.output("
disconnected");
}
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);
})