summaryrefslogtreecommitdiff
path: root/kvmd/web/js/stream.js
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-07-15 11:21:44 +0300
committerDevaev Maxim <[email protected]>2018-07-15 11:21:44 +0300
commit999d3f245710013425cc2413f81d900ec1fc2f24 (patch)
tree07bf519cab5da1b522e8146a362724762c8a3e7c /kvmd/web/js/stream.js
parent4122ecdb55abae00f2168d27df5f88527fc02341 (diff)
big js refactoring
Diffstat (limited to 'kvmd/web/js/stream.js')
-rw-r--r--kvmd/web/js/stream.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/kvmd/web/js/stream.js b/kvmd/web/js/stream.js
new file mode 100644
index 00000000..afaed1ae
--- /dev/null
+++ b/kvmd/web/js/stream.js
@@ -0,0 +1,53 @@
+var stream = new function() {
+ var __prev_state = false;
+
+ this.startPoller = function() {
+ var http = tools.makeRequest("GET", "/streamer/?action=snapshot", function() {
+ if (http.readyState === 2 || http.readyState === 4) {
+ var status = http.status;
+ http.onreadystatechange = null;
+ http.abort();
+ if (status !== 200) {
+ tools.info("Refreshing stream ...");
+ __prev_state = false;
+ $("stream-image").className = "stream-image-inactive";
+ $("stream-led").className = "led-off";
+ } else if (!__prev_state) {
+ __refreshImage();
+ __prev_state = true;
+ $("stream-image").className = "stream-image-active";
+ $("stream-led").className = "led-on";
+ }
+ }
+ });
+ setTimeout(stream.startPoller, 2000);
+ };
+
+// this.setActive = function(active) {
+// $("stream-image").className = (active ? "stream-image-active" : "stream-image-inactive");
+// };
+
+ this.clickResetButton = function(el_button) {
+ tools.setButtonBusy(el_button, true);
+ var http = tools.makeRequest("POST", "/kvmd/streamer/reset", function() {
+ if (http.readyState === 4) {
+ if (http.status !== 200) {
+ alert("Can't reset stream:", http.responseText);
+ }
+ tools.setButtonBusy(el_button, false);
+ }
+ });
+ };
+
+ var __refreshImage = function() {
+ var http = tools.makeRequest("GET", "/kvmd/streamer", function() {
+ if (http.readyState === 4 && http.status === 200) {
+ size = JSON.parse(http.responseText).result.size;
+ el_stream_image = $("stream-image");
+ el_stream_image.style.width = size.width + "px";
+ el_stream_image.style.height = size.height + "px";
+ el_stream_image.src = "/streamer/?action=stream&time=" + new Date().getTime();
+ }
+ });
+ };
+};