summaryrefslogtreecommitdiff
path: root/kvmd/web
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-07-13 17:54:15 +0000
committerDevaev Maxim <[email protected]>2018-07-13 17:54:15 +0000
commite118d270dfb310498d2135f5af7c6b86bdc161c7 (patch)
tree1172c6ef98ab67b6e579cf6a373691f9d91797bc /kvmd/web
parent9e1f9ae853a733e0c0178bf1b8e03c6e6db7b2dd (diff)
exclusive region-based access for soma apis
Diffstat (limited to 'kvmd/web')
-rw-r--r--kvmd/web/js/kvmd.js42
1 files changed, 20 insertions, 22 deletions
diff --git a/kvmd/web/js/kvmd.js b/kvmd/web/js/kvmd.js
index f9a789f3..a4d75387 100644
--- a/kvmd/web/js/kvmd.js
+++ b/kvmd/web/js/kvmd.js
@@ -154,17 +154,16 @@ function clickAtxButton(el_button) {
if (button && confirm(confirm_msg)) {
__setAtxButtonsBusy(true);
- var http = new XMLHttpRequest();
- http.open("POST", "/kvmd/atx/click?button=" + button, true);
- http.onreadystatechange = function() {
+ var http = __request("POST", "/kvmd/atx/click?button=" + button, function() {
if (http.readyState == 4) {
- if (http.status != 200) {
+ if (http.status == 409) {
+ alert("Performing another ATX operation for other client, please try again later");
+ } else if (http.status != 200) {
alert("Click error: " + http.responseText);
}
- __setAtxButtonsBusy(false);
+ __setAtxButtonsBusy(false);
}
- }
- http.send();
+ });
}
}
@@ -181,9 +180,7 @@ function __setAtxButtonsBusy(busy) {
// -----------------------------------------------------------------------------
function pollStreamer() {
- var http = new XMLHttpRequest();
- http.open("GET", "/streamer/?action=snapshot", true);
- http.onreadystatechange = function() {
+ var http = __request("GET", "/streamer/?action=snapshot", function() {
if (http.readyState == 2 || http.readyState == 4) {
var status = http.status;
http.onreadystatechange = null;
@@ -198,16 +195,13 @@ function pollStreamer() {
pollStreamer.last = true;
}
}
- }
- http.send();
+ });
setTimeout(pollStreamer, 2000);
}
pollStreamer.last = false;
function __refreshStreamer() {
- var http = new XMLHttpRequest();
- http.open("GET", "/kvmd/streamer", true);
- http.onreadystatechange = function() {
+ var http = __request("GET", "/kvmd/streamer", function() {
if (http.readyState == 4 && http.status == 200) {
size = JSON.parse(http.responseText).result.size;
el_stream_box = document.getElementById("stream-image");
@@ -215,27 +209,31 @@ function __refreshStreamer() {
el_stream_box.style.height = size.height + "px";
document.getElementById("stream-image").src = "/streamer/?action=stream&time=" + new Date().getTime();
}
- }
- http.send();
+ });
}
function clickResetStreamerButton(el_button) {
__setButtonBusy(el_button, true);
- var http = new XMLHttpRequest();
- http.open("POST", "/kvmd/streamer/reset", true);
- http.onreadystatechange = function() {
+ var http = __request("POST", "/kvmd/streamer/reset", function() {
if (http.readyState == 4) {
if (http.status != 200) {
alert("Can't reset streamer: " + http.responseText);
}
__setButtonBusy(el_button, false);
}
- }
- http.send();
+ });
}
// -----------------------------------------------------------------------------
+function __request(method, url, callback) {
+ var http = new XMLHttpRequest();
+ http.open(method, url, true)
+ http.onreadystatechange = callback;
+ http.send();
+ return http;
+}
+
function __setButtonBusy(el_button, busy) {
el_button.disabled = busy;
el_button.style.cursor = (busy ? "wait" : "default");