From 735cb4909f3a9b5cc7bfd69afec5777357d4e9b3 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Wed, 11 May 2016 00:24:44 +0000 Subject: [PATCH] Send reboots, handle reconnecting --- server/static/control.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/server/static/control.js b/server/static/control.js index bf88e54..4d1ee68 100644 --- a/server/static/control.js +++ b/server/static/control.js @@ -4,12 +4,21 @@ let ImageController = function(container) { this.container_ = container; this.image_types_ = new Map(); - this.ws_ = new WebSocket('wss://' + location.host + '/ws/master', 'iconograph-master'); - this.ws_.addEventListener('message', (e) => this.onMessage_(JSON.parse(e.data))); + this.connect_(); this.timer_ = setInterval((e) => this.onTick_(), 250); }; +ImageController.prototype.connect_ = function() { + this.ws_ = new WebSocket('wss://' + location.host + '/ws/master', 'iconograph-master'); + this.ws_.addEventListener('message', (e) => this.onMessage_(JSON.parse(e.data))); + this.ws_.addEventListener('close', (e) => this.onClose_()); +}; + +ImageController.prototype.onClose_ = function() { + setTimeout((e) => this.connect_(), 5000); +}; + ImageController.prototype.onMessage_ = function(msg) { switch (msg['type']) { case 'image_types': @@ -83,10 +92,15 @@ ImageController.prototype.addInstance_ = function(type, hostname) { value.volume_id = this.createNode_(value.section, 'volumeID'); value.next_timestamp = this.createNode_(value.section, 'timestamp'); value.next_volume_id = this.createNode_(value.section, 'volumeID'); + value.reboot = this.createNode_(value.section, 'reboot', 'Reboot'); + value.volume_id.addEventListener( 'click', (e) => this.onVolumeIDClick_(e.target.innerText)); value.next_volume_id.addEventListener( 'click', (e) => this.onVolumeIDClick_(e.target.innerText)); + value.reboot.addEventListener( + 'click', (e) => this.sendReboot_(hostname)); + type.instances.set(hostname, value); }; @@ -108,6 +122,16 @@ ImageController.prototype.onVolumeIDClick_ = function(volume_id) { open(base_url.replace('VOLUMEID', volume_id)); }; +ImageController.prototype.sendReboot_ = function(hostname) { + this.ws_.send(JSON.stringify({ + 'type': 'command', + 'target': hostname, + 'data': { + 'command': 'reboot', + }, + })); +}; + ImageController.prototype.insertSorted_ = function(parent, new_child, key) { let insert_before = null; for (var i = 0; i < parent.childNodes.length; i++) {