summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-08-27 13:33:15 +0300
committerDevaev Maxim <[email protected]>2018-08-27 13:33:15 +0300
commit9a243eaa0402aebc61cd7a247a04b57bd8ec0ad3 (patch)
tree7fb8b66ac413ad516b517542cacb4895e41b8710 /kvmd
parenta8773eab1e8f82a7bd862492e5520dcb9690a5e0 (diff)
refactoring
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/web/js/hid.js36
-rw-r--r--kvmd/web/js/keyboard.js26
-rw-r--r--kvmd/web/js/main.js5
-rw-r--r--kvmd/web/js/mouse.js22
-rw-r--r--kvmd/web/js/ui.js33
5 files changed, 59 insertions, 63 deletions
diff --git a/kvmd/web/js/hid.js b/kvmd/web/js/hid.js
index eef503d1..50bbd5e7 100644
--- a/kvmd/web/js/hid.js
+++ b/kvmd/web/js/hid.js
@@ -12,6 +12,35 @@ function Hid() {
var __mouse = new Mouse();
var __init__ = function() {
+ var __hidden_attr = null;
+ var __visibility_change_attr = null;
+
+ if (typeof document.hidden !== "undefined") {
+ __hidden_attr = "hidden";
+ __visibility_change_attr = "visibilitychange";
+ } else if (typeof document.webkitHidden !== "undefined") {
+ __hidden_attr = "webkitHidden";
+ __visibility_change_attr = "webkitvisibilitychange";
+ } else if (typeof document.mozHidden !== "undefined") {
+ __hidden_attr = "mozHidden";
+ __visibility_change_attr = "mozvisibilitychange";
+ }
+
+ if (__visibility_change_attr) {
+ document.addEventListener(
+ __visibility_change_attr,
+ function() {
+ if (document[__hidden_attr]) {
+ __releaseAll();
+ }
+ },
+ false
+ );
+ }
+
+ window.onpagehide = __releaseAll;
+ window.onblur = __releaseAll;
+
if (window.navigator.clipboard && window.navigator.clipboard.readText) {
__chars_to_codes = __buildCharsToCodes();
$("pak-button").onclick = __pasteAsKeys;
@@ -33,12 +62,7 @@ function Hid() {
$("pak-button").disabled = !(window.navigator.clipboard && window.navigator.clipboard.readText && ws);
};
- self.updateLeds = function() {
- __keyboard.updateLeds();
- __mouse.updateLeds();
- };
-
- self.releaseAll = function() {
+ var __releaseAll = function() {
__keyboard.releaseAll();
};
diff --git a/kvmd/web/js/keyboard.js b/kvmd/web/js/keyboard.js
index 45a15ac0..f1296bed 100644
--- a/kvmd/web/js/keyboard.js
+++ b/kvmd/web/js/keyboard.js
@@ -20,9 +20,13 @@ function Keyboard() {
$("keyboard-window").onkeydown = (event) => __keyboardHandler(event, true);
$("keyboard-window").onkeyup = (event) => __keyboardHandler(event, false);
+ $("keyboard-window").onfocus = __updateLeds;
+ $("keyboard-window").onblur = __updateLeds;
$("stream-window").onkeydown = (event) => __keyboardHandler(event, true);
$("stream-window").onkeyup = (event) => __keyboardHandler(event, false);
+ $("stream-window").onfocus = __updateLeds;
+ $("stream-window").onblur = __updateLeds;
Array.prototype.forEach.call($$("key"), function(el_key) {
el_key.onmousedown = () => __clickHandler(el_key, true);
@@ -54,17 +58,7 @@ function Keyboard() {
self.releaseAll();
__ws = ws;
}
- self.updateLeds();
- };
-
- self.updateLeds = function() {
- if (__ws && (document.activeElement === $("stream-window") || document.activeElement === $("keyboard-window"))) {
- $("hid-keyboard-led").className = "led-on";
- $("hid-keyboard-led").title = "Keyboard captured";
- } else {
- $("hid-keyboard-led").className = "led-off";
- $("hid-keyboard-led").title = "Keyboard free";
- }
+ __updateLeds();
};
self.releaseAll = function() {
@@ -82,6 +76,16 @@ function Keyboard() {
));
};
+ var __updateLeds = function() {
+ if (__ws && (document.activeElement === $("stream-window") || document.activeElement === $("keyboard-window"))) {
+ $("hid-keyboard-led").className = "led-on";
+ $("hid-keyboard-led").title = "Keyboard captured";
+ } else {
+ $("hid-keyboard-led").className = "led-off";
+ $("hid-keyboard-led").title = "Keyboard free";
+ }
+ };
+
var __keyboardHandler = function(event, state) {
event.preventDefault();
var el_key = $(event.code);
diff --git a/kvmd/web/js/main.js b/kvmd/web/js/main.js
index a0008d53..a1cd8b5d 100644
--- a/kvmd/web/js/main.js
+++ b/kvmd/web/js/main.js
@@ -7,9 +7,8 @@ function main() {
) {
$("bad-browser-modal").style.visibility = "visible";
} else {
- var hid = new Hid();
- var ui = new Ui(hid);
- new Session(new Atx(), hid, new Msd());
+ var ui = new Ui();
+ new Session(new Atx(), new Hid(), new Msd());
new Stream(ui);
}
}
diff --git a/kvmd/web/js/mouse.js b/kvmd/web/js/mouse.js
index 1ba1f850..9ee92053 100644
--- a/kvmd/web/js/mouse.js
+++ b/kvmd/web/js/mouse.js
@@ -38,7 +38,17 @@ function Mouse() {
}
};
- self.updateLeds = function() {
+ var __hoverStream = function() {
+ __stream_hovered = true;
+ __updateLeds();
+ };
+
+ var __leaveStream = function() {
+ __stream_hovered = false;
+ __updateLeds();
+ };
+
+ var __updateLeds = function() {
if (__ws && __stream_hovered) {
$("hid-mouse-led").className = "led-on";
$("hid-mouse-led").title = "Mouse tracked";
@@ -48,16 +58,6 @@ function Mouse() {
}
};
- var __hoverStream = function() {
- __stream_hovered = true;
- self.updateLeds();
- };
-
- var __leaveStream = function() {
- __stream_hovered = false;
- self.updateLeds();
- };
-
var __touchHandler = function(event, state) {
if (state) {
var rect = event.touches[0].target.getBoundingClientRect();
diff --git a/kvmd/web/js/ui.js b/kvmd/web/js/ui.js
index 0fa2ccd3..94924d8c 100644
--- a/kvmd/web/js/ui.js
+++ b/kvmd/web/js/ui.js
@@ -1,4 +1,4 @@
-function Ui(hid) {
+function Ui() {
var self = this;
/********************************************************************************/
@@ -26,35 +26,6 @@ function Ui(hid) {
}
});
- var __hidden_attr = null;
- var __visibility_change_attr = null;
-
- if (typeof document.hidden !== "undefined") {
- __hidden_attr = "hidden";
- __visibility_change_attr = "visibilitychange";
- } else if (typeof document.webkitHidden !== "undefined") {
- __hidden_attr = "webkitHidden";
- __visibility_change_attr = "webkitvisibilitychange";
- } else if (typeof document.mozHidden !== "undefined") {
- __hidden_attr = "mozHidden";
- __visibility_change_attr = "mozvisibilitychange";
- }
-
- if (__visibility_change_attr) {
- document.addEventListener(
- __visibility_change_attr,
- function() {
- if (document[__hidden_attr]) {
- hid.releaseAll();
- }
- },
- false
- );
- }
-
- window.onpagehide = hid.releaseAll;
- window.onblur = hid.releaseAll;
-
window.onmouseup = __globalMouseButtonHandler;
// window.oncontextmenu = __globalMouseButtonHandler;
@@ -144,7 +115,6 @@ function Ui(hid) {
};
var __globalMouseButtonHandler = function(event) {
- hid.updateLeds();
if (!event.target.matches(".ctl-item")) {
for (var el_item = event.target; el_item && el_item !== document; el_item = el_item.parentNode) {
if (el_item.hasAttribute("data-force-hide-menu")) {
@@ -251,7 +221,6 @@ function Ui(hid) {
var __raiseWindow = function(el_window) {
el_window.focus();
- hid.updateLeds();
if (parseInt(el_window.style.zIndex) !== __top_z_index) {
var z_index = __top_z_index + 1;
el_window.style.zIndex = z_index;