diff options
Diffstat (limited to 'kvmd/web/js')
-rw-r--r-- | kvmd/web/js/atx.js | 26 | ||||
-rw-r--r-- | kvmd/web/js/msd.js | 24 | ||||
-rw-r--r-- | kvmd/web/js/session.js | 10 |
3 files changed, 51 insertions, 9 deletions
diff --git a/kvmd/web/js/atx.js b/kvmd/web/js/atx.js index 0779f584..0167ae6f 100644 --- a/kvmd/web/js/atx.js +++ b/kvmd/web/js/atx.js @@ -1,10 +1,22 @@ var atx = new function() { - this.setLedsState = function(leds) { - $("atx-power-led").className = (leds.power ? "led-on" : "led-off"); - $("atx-hdd-led").className = (leds.hdd ? "led-hdd-busy" : "led-off"); + this.loadInitialState = function() { + var http = tools.makeRequest("GET", "/kvmd/atx", function() { + if (http.readyState === 4) { + if (http.status === 200) { + atx.setButtonsBusy(JSON.parse(http.responseText).result.busy); + } else { + setTimeout(atx.loadInitialState, 1000); + } + } + }); + }; + + this.setState = function(state) { + $("atx-power-led").className = (state.leds.power ? "led-on" : "led-off"); + $("atx-hdd-led").className = (state.leds.hdd ? "led-hdd-busy" : "led-off"); }; - this.clearLeds = function() { + this.clearState = function() { [ "atx-power-led", "atx-hdd-led", @@ -35,7 +47,7 @@ var atx = new function() { } if (button && confirm(confirm_msg)) { - __setButtonsBusy(true); + // atx.setButtonsBusy(true); var http = tools.makeRequest("POST", "/kvmd/atx/click?button=" + button, function() { if (http.readyState === 4) { if (http.status === 409) { @@ -43,13 +55,13 @@ var atx = new function() { } else if (http.status !== 200) { alert("Click error:", http.responseText); } - __setButtonsBusy(false); + // atx.setButtonsBusy(false); } }, timeout); } }; - var __setButtonsBusy = function(busy) { + this.setButtonsBusy = function(busy) { [ "atx-power-button", "atx-power-button-long", diff --git a/kvmd/web/js/msd.js b/kvmd/web/js/msd.js new file mode 100644 index 00000000..5ae851ea --- /dev/null +++ b/kvmd/web/js/msd.js @@ -0,0 +1,24 @@ +var msd = new function() { + this.loadInitialState = function() { + var http = tools.makeRequest("GET", "/kvmd/msd", function() { + if (http.readyState === 4) { + if (http.status === 200) { + msd.setState(JSON.parse(http.responseText).result); + } else { + setTimeout(msd.loadInitialState, 1000); + } + } + }); + }; + + this.setState = function(state) { + if (state.connected_to == "server") { + cls = "led-on"; + } else if (state.busy) { + cls = "led-msd-writing"; + } else { + cls = "led-off"; + } + $("msd-led").className = cls; + }; +}; diff --git a/kvmd/web/js/session.js b/kvmd/web/js/session.js index b4642b62..33c8af60 100644 --- a/kvmd/web/js/session.js +++ b/kvmd/web/js/session.js @@ -13,6 +13,8 @@ var session = new function() { var __wsOpenHandler = function(event) { tools.debug("WebSocket opened:", event); + atx.loadInitialState(); + msd.loadInitialState(); hid.installCapture(__ws); __missed_heartbeats = 0; __ping_timer = setInterval(__pingServer, 1000); @@ -25,7 +27,11 @@ var session = new function() { __missed_heartbeats = 0; } else if (event.msg_type === "event") { if (event.msg.event === "atx_state") { - atx.setLedsState(event.msg.event_attrs.leds); + atx.setState(event.msg.event_attrs); + // } else if (event.msg.event === "atx_click") { + // atx.setButtonsBusy(event.msg.event_attrs.button); + } else if (event.msg.event === "msd_state") { + msd.setState(event.msg.event_attrs); } } }; @@ -46,7 +52,7 @@ var session = new function() { __ping_timer = null; } hid.clearCapture(); - atx.clearLeds(); + atx.clearState(); __ws = null; setTimeout(session.startPoller, 1000); }; |