summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-07-13 02:23:35 +0000
committerDevaev Maxim <[email protected]>2018-07-13 02:23:35 +0000
commit9c44852aa1948a991e0bf1956badd17bde912089 (patch)
tree2b4f6b568c567b13bf32f79adc795d82a98a6522
parent796d35ed3b1688c3e4aef1984439291c4565a4aa (diff)
dynamic stream resolution
-rw-r--r--kvmd/web/css/main.css4
-rw-r--r--kvmd/web/index.html2
-rw-r--r--kvmd/web/js/kvmd.js30
3 files changed, 29 insertions, 7 deletions
diff --git a/kvmd/web/css/main.css b/kvmd/web/css/main.css
index 65169379..832a3645 100644
--- a/kvmd/web/css/main.css
+++ b/kvmd/web/css/main.css
@@ -6,8 +6,8 @@
text-align: left;
}
.stream-box .stream-image {
- width: 720px;
- height: 576px;
+ width: 640px;
+ height: 480px;
border: 1px solid grey;
display: inline-block;
}
diff --git a/kvmd/web/index.html b/kvmd/web/index.html
index d5538943..7d85f26d 100644
--- a/kvmd/web/index.html
+++ b/kvmd/web/index.html
@@ -15,7 +15,7 @@
</script>
<body>
- <div class="stream-box">
+ <div id="stream-box" class="stream-box">
<img src="/streamer/?action=stream" id="stream-image" class="stream-image" alt="" />
</div>
diff --git a/kvmd/web/js/kvmd.js b/kvmd/web/js/kvmd.js
index dc69bc73..24891cd4 100644
--- a/kvmd/web/js/kvmd.js
+++ b/kvmd/web/js/kvmd.js
@@ -11,8 +11,9 @@ function runKvmdSession() {
event = JSON.parse(event.data);
if (event.msg_type == "event") {
if (event.msg.event == "atx_state") {
- document.getElementById("power-led").className = "power-led-" + (event.msg.event_attrs.leds.power ? "on" : "off");
- document.getElementById("hdd-led").className = "hdd-led-" + (event.msg.event_attrs.leds.hdd ? "on" : "off");
+ leds = event.msg.event_attrs.leds;
+ document.getElementById("power-led").className = "power-led-" + (leds.power ? "on" : "off");
+ document.getElementById("hdd-led").className = "hdd-led-" + (leds.hdd ? "on" : "off");
}
}
};
@@ -97,15 +98,36 @@ function pollStreamer() {
http.open("GET", "/streamer/?action=snapshot", true);
http.onreadystatechange = function() {
if (http.readyState == 2) {
+ var status = http.status;
http.abort();
- if (http.status != 200) {
- document.getElementById("stream-image").src = "/streamer/?action=stream&time=" + new Date().getTime();
+ if (status != 200) {
+ console.log("Refreshing streamer ...");
+ pollStreamer.last = false;
+ } else if (!pollStreamer.last) {
+ __refreshStremaer();
+ pollStreamer.last = true;
}
}
}
http.send();
setTimeout(pollStreamer, 2000);
}
+pollStreamer.last = false;
+
+function __refreshStremaer() {
+ var http = new XMLHttpRequest();
+ http.open("GET", "/kvmd/streamer", true);
+ http.onreadystatechange = function() {
+ if (http.readyState == 4 && http.status == 200) {
+ size = JSON.parse(http.responseText).result.size;
+ el_stream_box = document.getElementById("stream-image");
+ el_stream_box.style.width = size.width + "px";
+ el_stream_box.style.height = size.height + "px";
+ document.getElementById("stream-image").src = "/streamer/?action=stream&time=" + new Date().getTime();
+ }
+ }
+ http.send();
+}
function resetStreamer() {
var http = new XMLHttpRequest();