summaryrefslogtreecommitdiff
path: root/kvmd/web/js/hid.js
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-08-13 03:56:05 +0300
committerDevaev Maxim <[email protected]>2018-08-13 03:56:05 +0300
commitb2a05bd1abec6b0d95149a6b7716d2fb7951d4ad (patch)
tree670e0628ace8d9728826af938390edb06cb0970c /kvmd/web/js/hid.js
parent798bc37fcec208c247e0730c0e37735205bb6dcf (diff)
refactoring
Diffstat (limited to 'kvmd/web/js/hid.js')
-rw-r--r--kvmd/web/js/hid.js50
1 files changed, 33 insertions, 17 deletions
diff --git a/kvmd/web/js/hid.js b/kvmd/web/js/hid.js
index 86d3931d..319b0327 100644
--- a/kvmd/web/js/hid.js
+++ b/kvmd/web/js/hid.js
@@ -1,36 +1,48 @@
-var hid = new function() {
+function Hid() {
+ var self = this;
+
+ /********************************************************************************/
+
var __ws = null;
+
var __chars_to_codes = {};
var __codes_delay = 50;
- this.init = function() {
- keyboard.init();
- mouse.init();
+ var __keyboard = new Keyboard();
+ var __mouse = new Mouse();
+
+ var __init__ = function() {
if (window.navigator.clipboard && window.navigator.clipboard.readText) {
__chars_to_codes = __buildCharsToCodes();
$("pak-button").onclick = __pasteAsKeys;
} else {
- $("pak-button").title = "Your browser does not support the Clipboard API.\nUse Google Chrome or Chromium.";
+ $("pak-button").title = $("pak-led").title = "Your browser does not support the Clipboard API.\nUse Google Chrome or Chromium.";
}
+
+ Array.prototype.forEach.call($$("shortcut"), function(el_shortcut) {
+ el_shortcut.onclick = () => __emitShortcut(el_shortcut.getAttribute("data-shortcut").split(" "));
+ });
};
- this.setSocket = function(ws) {
+ /********************************************************************************/
+
+ self.setSocket = function(ws) {
__ws = ws;
- keyboard.setSocket(ws);
- mouse.setSocket(ws);
+ __keyboard.setSocket(ws);
+ __mouse.setSocket(ws);
$("pak-button").disabled = !(window.navigator.clipboard && window.navigator.clipboard.readText && ws);
};
- this.updateLeds = function() {
- keyboard.updateLeds();
- mouse.updateLeds();
+ self.updateLeds = function() {
+ __keyboard.updateLeds();
+ __mouse.updateLeds();
};
- this.releaseAll = function() {
- keyboard.releaseAll();
+ self.releaseAll = function() {
+ __keyboard.releaseAll();
};
- this.emitShortcut = function(...codes) {
+ var __emitShortcut = function(codes) {
return new Promise(function(resolve) {
tools.debug("Emitting keys:", codes);
@@ -44,7 +56,7 @@ var hid = new function() {
var index = 0;
var iterate = () => setTimeout(function() {
- keyboard.fireEvent(raw_events[index].code, raw_events[index].state);
+ __keyboard.fireEvent(raw_events[index].code, raw_events[index].state);
++index;
if (index < raw_events.length) {
iterate();
@@ -118,18 +130,20 @@ var hid = new function() {
if (codes_count <= 256 || confirm(confirm_msg)) {
$("pak-button").disabled = true;
$("pak-led").className = "led-pak-typing";
+ $("pak-led").title = "Autotyping...";
tools.debug("Paste-as-keys:", clipboard_text);
var index = 0;
var iterate = function() {
- hid.emitShortcut(...clipboard_codes[index]).then(function() {
+ __emitShortcut(clipboard_codes[index]).then(function() {
++index;
if (index < clipboard_codes.length && __ws) {
iterate();
} else {
$("pak-button").disabled = false;
$("pak-led").className = "led-off";
+ $("pak-led").title = "";
}
});
};
@@ -138,4 +152,6 @@ var hid = new function() {
}
});
};
-};
+
+ __init__();
+}