summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-09-29 19:57:29 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-09-29 20:57:35 (GMT)
commit8dc413a488c300c7a018a15e9c71b62cdd2d9ac0 (patch)
treec8541109e409b5f9cab4b777b64f8b4836a03682 /www/js
parentc6e2519b69bf8d0fb6560cdb51329a66344d7601 (diff)
added contoler for rhctl
Diffstat (limited to 'www/js')
-rw-r--r--www/js/rhctl.js50
1 files changed, 49 insertions, 1 deletions
diff --git a/www/js/rhctl.js b/www/js/rhctl.js
index c70f8ee..5b5b438 100644
--- a/www/js/rhctl.js
+++ b/www/js/rhctl.js
@@ -21,6 +21,54 @@
'use strict';
+function Rhctl() {
+ this.state = 'NEW';
+
+ this.sock_onmessage = function(event) {
+ var msg = JSON.parse(event.data);
+ if (msg.RESPONSE_CODE != 200) {
+ console.log("got error message: ", event.data)
+ } else {
+ switch(msg.TYPE) {
+ case 'state':
+ $('#rhctl').text(JSON.stringify(msg.STATE, null, '\t'));
+ break;
+ case 'ack':
+ break;
+ default:
+ console.log("rhctl: got unexpected message type '" + msg.TYPE + "'")
+ }
+ }
+ }
+
+ this.sock_onopen = function() {
+ this.state = 'CONNECTED';
+ console.log('rhctl: ' + this.state)
+ this.sock.onmessage = this.sock_onmessage.bind(this);
+ this.sock.send(JSON.stringify({ COMMAND: 'subscribe', ARGS: [ 'state' ] }));
+ this.sock.send(JSON.stringify({ COMMAND: 'state' }));
+ }
+
+ this.sock_onclose = function(event) {
+ this.sock.close();
+ delete this.sock;
+ setTimeout(this.connect.bind(this), 1000);
+ this.state = 'RECONNECTING';
+ console.log('rhctl: ' + this.state)
+ }
+
+ this.connect = function() {
+ this.sock = new WebSocket('wss://' + window.location.host + '/rhctl/socket');
+ this.sock.onopen = this.sock_onopen.bind(this);
+ this.sock.onclose = this.sock_onclose.bind(this);
+ this.state = 'CONNECTING';
+ console.log('rhctl: ' + this.state)
+ }
+}
+
+var rhctl = new Rhctl();
+
function rhctl_init() {
- $('#rhctl').append($('<h2>').text("coming soon"));
+ $('#rhctl').text("loading...");
+ rhctl.connect();
}