summaryrefslogtreecommitdiff
path: root/web/share/js/kvm
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-04-25 00:18:10 +0300
committerDevaev Maxim <[email protected]>2019-04-25 00:18:10 +0300
commit73bfd715e3d83b777530252ef06e6fad702dd036 (patch)
treecfd9b297a7d8883022c65224e1ca2bd04598f971 /web/share/js/kvm
parent3d64401b111d863072c74e81e49de68885c0e084 (diff)
refactoring
Diffstat (limited to 'web/share/js/kvm')
-rw-r--r--web/share/js/kvm/atx.js2
-rw-r--r--web/share/js/kvm/hid.js70
-rw-r--r--web/share/js/kvm/keyboard.js6
-rw-r--r--web/share/js/kvm/main.js2
-rw-r--r--web/share/js/kvm/mouse.js18
-rw-r--r--web/share/js/kvm/msd.js14
-rw-r--r--web/share/js/kvm/session.js6
-rw-r--r--web/share/js/kvm/stream.js36
8 files changed, 77 insertions, 77 deletions
diff --git a/web/share/js/kvm/atx.js b/web/share/js/kvm/atx.js
index c649ae4e..b0da761e 100644
--- a/web/share/js/kvm/atx.js
+++ b/web/share/js/kvm/atx.js
@@ -56,7 +56,7 @@ function Atx() {
var __clickButton = function(button, confirm_msg) {
wm.confirm(confirm_msg).then(function(ok) {
if (ok) {
- var http = tools.makeRequest("POST", "/kvmd/atx/click?button=" + button, function() {
+ let http = tools.makeRequest("POST", "/kvmd/atx/click?button=" + button, function() {
if (http.readyState === 4) {
if (http.status === 409) {
wm.error("Performing another ATX operation for other client.<br>Please try again later");
diff --git a/web/share/js/kvm/hid.js b/web/share/js/kvm/hid.js
index c731843c..17b21ca9 100644
--- a/web/share/js/kvm/hid.js
+++ b/web/share/js/kvm/hid.js
@@ -34,25 +34,25 @@ function Hid() {
var __mouse = new Mouse();
var __init__ = function() {
- var __hidden_attr = null;
- var __visibility_change_attr = null;
+ let hidden_attr = null;
+ let visibility_change_attr = null;
if (typeof document.hidden !== "undefined") {
- __hidden_attr = "hidden";
- __visibility_change_attr = "visibilitychange";
+ hidden_attr = "hidden";
+ visibility_change_attr = "visibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
- __hidden_attr = "webkitHidden";
- __visibility_change_attr = "webkitvisibilitychange";
+ hidden_attr = "webkitHidden";
+ visibility_change_attr = "webkitvisibilitychange";
} else if (typeof document.mozHidden !== "undefined") {
- __hidden_attr = "mozHidden";
- __visibility_change_attr = "mozvisibilitychange";
+ hidden_attr = "mozHidden";
+ visibility_change_attr = "mozvisibilitychange";
}
- if (__visibility_change_attr) {
+ if (visibility_change_attr) {
document.addEventListener(
- __visibility_change_attr,
+ visibility_change_attr,
function() {
- if (document[__hidden_attr]) {
+ if (document[hidden_attr]) {
__releaseAll();
}
},
@@ -68,9 +68,9 @@ function Hid() {
tools.setOnClick($("hid-pak-button"), __clickPasteAsKeysButton);
tools.setOnClick($("hid-reset-button"), __clickResetButton);
- tools.forEach($$$("[data-shortcut]"), function(el_shortcut) {
+ for (let el_shortcut of $$$("[data-shortcut]")) {
tools.setOnClick(el_shortcut, () => __emitShortcut(el_shortcut.getAttribute("data-shortcut").split(" ")));
- });
+ }
};
/************************************************************************/
@@ -98,16 +98,16 @@ function Hid() {
return new Promise(function(resolve) {
tools.debug("HID: emitting keys:", codes);
- var raw_events = [];
+ let raw_events = [];
[[codes, true], [codes.slice().reverse(), false]].forEach(function(op) {
- var [op_codes, state] = op;
- op_codes.forEach(function(code) {
+ let [op_codes, state] = op;
+ for (let code of op_codes) {
raw_events.push({code: code, state: state});
- });
+ }
});
- var index = 0;
- var iterate = () => setTimeout(function() {
+ let index = 0;
+ let iterate = () => setTimeout(function() {
__keyboard.emit(raw_events[index].code, raw_events[index].state);
++index;
if (index < raw_events.length) {
@@ -121,7 +121,7 @@ function Hid() {
};
var __buildCharsToCodes = function() {
- var chars_to_codes = {
+ let chars_to_codes = {
"\n": ["Enter"],
"\t": ["Tab"],
" ": ["Space"],
@@ -148,10 +148,10 @@ function Hid() {
"=": ["Equal"], "+": ["ShiftLeft", "Equal"],
};
- for (var ch = "a".charCodeAt(0); ch <= "z".charCodeAt(0); ++ch) {
- var low = String.fromCharCode(ch);
- var up = low.toUpperCase();
- var code = "Key" + up;
+ for (let ch = "a".charCodeAt(0); ch <= "z".charCodeAt(0); ++ch) {
+ let low = String.fromCharCode(ch);
+ let up = low.toUpperCase();
+ let code = "Key" + up;
chars_to_codes[low] = [code];
chars_to_codes[up] = ["ShiftLeft", code];
}
@@ -160,20 +160,20 @@ function Hid() {
};
var __clickPasteAsKeysButton = function() {
- var text = $("hid-pak-text").value.replace(/[^\x00-\x7F]/g, ""); // eslint-disable-line no-control-regex
+ let text = $("hid-pak-text").value.replace(/[^\x00-\x7F]/g, ""); // eslint-disable-line no-control-regex
if (text) {
- var clipboard_codes = [];
- var codes_count = 0;
- [...text].forEach(function(ch) {
- var codes = __chars_to_codes[ch];
+ let clipboard_codes = [];
+ let codes_count = 0;
+ for (let ch of text) {
+ let codes = __chars_to_codes[ch];
if (codes) {
codes_count += codes.length;
clipboard_codes.push(codes);
}
- });
- var time = __codes_delay * codes_count * 2 / 1000;
+ }
+ let time = __codes_delay * codes_count * 2 / 1000;
- var confirm_msg = `
+ let confirm_msg = `
You are going to automatically type ${codes_count} characters from the system clipboard.
It will take ${time} seconds.<br>
<br>
@@ -189,8 +189,8 @@ function Hid() {
tools.debug("HID: paste-as-keys:", text);
- var index = 0;
- var iterate = function() {
+ let index = 0;
+ let iterate = function() {
__emitShortcut(clipboard_codes[index]).then(function() {
++index;
if (index < clipboard_codes.length && __ws) {
@@ -215,7 +215,7 @@ function Hid() {
var __clickResetButton = function() {
wm.confirm("Are you sure you want to reset HID (keyboard & mouse)?").then(function(ok) {
if (ok) {
- var http = tools.makeRequest("POST", "/kvmd/hid/reset", function() {
+ let http = tools.makeRequest("POST", "/kvmd/hid/reset", function() {
if (http.readyState === 4) {
if (http.status !== 200) {
wm.error("HID reset error:<br>", http.responseText);
diff --git a/web/share/js/kvm/keyboard.js b/web/share/js/kvm/keyboard.js
index 23d5665d..1a4563af 100644
--- a/web/share/js/kvm/keyboard.js
+++ b/web/share/js/kvm/keyboard.js
@@ -81,12 +81,12 @@ function Keyboard() {
};
var __updateLeds = function() {
- var is_captured = (
+ let is_captured = (
$("stream-window").classList.contains("window-active")
|| $("keyboard-window").classList.contains("window-active")
);
- var led = "led-gray";
- var title = "Keyboard free";
+ let led = "led-gray";
+ let title = "Keyboard free";
if (__ws) {
if (__online) {
diff --git a/web/share/js/kvm/main.js b/web/share/js/kvm/main.js
index 97e3f62c..308b34c0 100644
--- a/web/share/js/kvm/main.js
+++ b/web/share/js/kvm/main.js
@@ -25,7 +25,7 @@ var wm;
function main() {
if (checkBrowser()) {
window.onbeforeunload = function(event) {
- var text = "Are you sure you want to close Pi-KVM session?";
+ let text = "Are you sure you want to close Pi-KVM session?";
event.returnValue = text;
return text;
};
diff --git a/web/share/js/kvm/mouse.js b/web/share/js/kvm/mouse.js
index e63a639a..c2d961e6 100644
--- a/web/share/js/kvm/mouse.js
+++ b/web/share/js/kvm/mouse.js
@@ -85,9 +85,9 @@ function Mouse() {
};
var __updateLeds = function() {
- var is_captured = (__stream_hovered || tools.browser.is_ios);
- var led = "led-gray";
- var title = "Mouse free";
+ let is_captured = (__stream_hovered || tools.browser.is_ios);
+ let led = "led-gray";
+ let title = "Mouse free";
if (__ws) {
if (__online) {
@@ -120,7 +120,7 @@ function Mouse() {
var __streamTouchMoveHandler = function(event) {
event.preventDefault();
if (event.touches[0].target && event.touches[0].target.getBoundingClientRect) {
- var rect = event.touches[0].target.getBoundingClientRect();
+ let rect = event.touches[0].target.getBoundingClientRect();
__current_pos = {
x: Math.round(event.touches[0].clientX - rect.left),
y: Math.round(event.touches[0].clientY - rect.top),
@@ -130,7 +130,7 @@ function Mouse() {
};
var __streamMoveHandler = function(event) {
- var rect = event.target.getBoundingClientRect();
+ let rect = event.target.getBoundingClientRect();
__current_pos = {
x: Math.round(event.clientX - rect.left),
y: Math.round(event.clientY - rect.top),
@@ -151,10 +151,10 @@ function Mouse() {
};
var __sendMove = function() {
- var pos = __current_pos;
+ let pos = __current_pos;
if (pos.x !== __sent_pos.x || pos.y !== __sent_pos.y) {
- var el_stream_image = $("stream-image");
- var to = {
+ let el_stream_image = $("stream-image");
+ let to = {
x: __translate(pos.x, 0, el_stream_image.clientWidth, -32768, 32767),
y: __translate(pos.y, 0, el_stream_image.clientHeight, -32768, 32767),
};
@@ -180,7 +180,7 @@ function Mouse() {
event.preventDefault();
}
- var delta = {x: 0, y: 0};
+ let delta = {x: 0, y: 0};
__wheel_delta.y += event.deltaY;
if (Math.abs(__wheel_delta.y) >= 100) {
diff --git a/web/share/js/kvm/msd.js b/web/share/js/kvm/msd.js
index d1dfac08..09dfd7bf 100644
--- a/web/share/js/kvm/msd.js
+++ b/web/share/js/kvm/msd.js
@@ -52,7 +52,7 @@ function Msd() {
};
var __clickUploadNewImageButton = function() {
- var form_data = new FormData();
+ let form_data = new FormData();
form_data.append("image_name", __image_file.name);
form_data.append("image_data", __image_file);
@@ -74,7 +74,7 @@ function Msd() {
};
var __clickSwitchButton = function(to) {
- var http = tools.makeRequest("POST", "/kvmd/msd/connect?to=" + to, function() {
+ let http = tools.makeRequest("POST", "/kvmd/msd/connect?to=" + to, function() {
if (http.readyState === 4) {
if (http.status !== 200) {
wm.error("Switch error:<br>", http.responseText);
@@ -87,8 +87,8 @@ function Msd() {
};
var __selectNewImageFile = function() {
- var el_input = $("msd-select-new-image-file");
- var image_file = (el_input.files.length ? el_input.files[0] : null);
+ let el_input = $("msd-select-new-image-file");
+ let image_file = (el_input.files.length ? el_input.files[0] : null);
if (image_file && image_file.size > __state.info.size) {
wm.error("New image is too big for your Mass Storage Device.<br>Maximum:", __formatSize(__state.info.size));
el_input.value = "";
@@ -101,7 +101,7 @@ function Msd() {
var __clickResetButton = function() {
wm.confirm("Are you sure you want to reset Mass Storage Device?").then(function(ok) {
if (ok) {
- var http = tools.makeRequest("POST", "/kvmd/msd/reset", function() {
+ let http = tools.makeRequest("POST", "/kvmd/msd/reset", function() {
if (http.readyState === 4) {
if (http.status !== 200) {
wm.error("MSD reset error:<br>", http.responseText);
@@ -196,7 +196,7 @@ function Msd() {
var __formatSize = function(size) {
if (size > 0) {
- var index = Math.floor( Math.log(size) / Math.log(1024) );
+ let index = Math.floor( Math.log(size) / Math.log(1024) );
return (size / Math.pow(1024, index)).toFixed(2) * 1 + " " + ["B", "kB", "MB", "GB", "TB"][index];
} else {
return 0;
@@ -217,7 +217,7 @@ function Msd() {
var __uploadProgress = function(event) {
if(event.lengthComputable) {
- var percent = Math.round((event.loaded * 100) / event.total);
+ let percent = Math.round((event.loaded * 100) / event.total);
$("msd-progress").setAttribute("data-label", percent + "%");
$("msd-progress-value").style.width = percent + "%";
}
diff --git a/web/share/js/kvm/session.js b/web/share/js/kvm/session.js
index 57946b56..adeb330e 100644
--- a/web/share/js/kvm/session.js
+++ b/web/share/js/kvm/session.js
@@ -43,7 +43,7 @@ function Session() {
var __setKvmdInfo = function(state) {
if (state.meta) {
- var text = JSON.stringify(state.meta, undefined, 4).replace(/ /g, "&nbsp;").replace(/\n/g, "<br>");
+ let text = JSON.stringify(state.meta, undefined, 4).replace(/ /g, "&nbsp;").replace(/\n/g, "<br>");
$("about-meta").innerHTML = `
<span class="code-comment">// The Pi-KVM metadata.<br>
// You can get this json using handle <a target="_blank" href="/kvmd/info">/kvmd/info</a>.<br>
@@ -69,10 +69,10 @@ function Session() {
$("link-led").className = "led-yellow";
$("link-led").title = "Connecting...";
- var http = tools.makeRequest("GET", "/kvmd/auth/check", function() {
+ let http = tools.makeRequest("GET", "/kvmd/auth/check", function() {
if (http.readyState === 4) {
if (http.status === 200) {
- var proto = (location.protocol === "https:" ? "wss" : "ws");
+ let proto = (location.protocol === "https:" ? "wss" : "ws");
__ws = new WebSocket(`${proto}://${location.host}/kvmd/ws`);
__ws.onopen = __wsOpenHandler;
__ws.onmessage = __wsMessageHandler;
diff --git a/web/share/js/kvm/stream.js b/web/share/js/kvm/stream.js
index f804d555..e34fc7dc 100644
--- a/web/share/js/kvm/stream.js
+++ b/web/share/js/kvm/stream.js
@@ -62,9 +62,9 @@ function Streamer() {
self.setState = function(state) {
if (state && state.state) {
- var encoder = state.state.encoder;
- var source = state.state.source;
- var stream = state.state.stream;
+ let encoder = state.state.encoder;
+ let source = state.state.source;
+ let stream = state.state.stream;
if (!__prev) {
$("stream-quality-slider").activated = false;
@@ -96,7 +96,7 @@ function Streamer() {
}
}
- var stream_client = tools.getCookie("stream_client");
+ let stream_client = tools.getCookie("stream_client");
if (!__client_id && stream_client && stream_client.startsWith(__client_key + "/")) {
tools.info("Stream: found acceptable stream_client cookie:", stream_client);
__client_id = stream_client.slice(stream_client.indexOf("/") + 1);
@@ -109,7 +109,7 @@ function Streamer() {
}
if (!__prev) {
- var path = "/streamer/stream?key=" + __client_key;
+ let path = "/streamer/stream?key=" + __client_key;
if (tools.browser.is_safari || tools.browser.is_ios) {
// uStreamer fix for WebKit
tools.info("Stream: using dual_final_frames=1 to fix WebKit MJPG bugs");
@@ -165,10 +165,10 @@ function Streamer() {
};
var __updateStreamHeader = function(online) {
- var el_grab = document.querySelector("#stream-window-header .window-grab");
- var el_info = $("stream-info");
+ let el_grab = document.querySelector("#stream-window-header .window-grab");
+ let el_info = $("stream-info");
if (online) {
- var fps_suffix = (__client_fps >= 0 ? ` / ${__client_fps} fps` : "");
+ let fps_suffix = (__client_fps >= 0 ? ` / ${__client_fps} fps` : "");
el_grab.innerHTML = el_info.innerHTML = `Stream &ndash; ${__resolution.width}x${__resolution.height}${fps_suffix}`;
} else {
el_grab.innerHTML = el_info.innerHTML = "Stream &ndash; offline";
@@ -176,7 +176,7 @@ function Streamer() {
};
var __clickScreenshotButton = function() {
- var el_a = document.createElement("a");
+ let el_a = document.createElement("a");
el_a.href = "/streamer/snapshot";
el_a.target = "_blank";
document.body.appendChild(el_a);
@@ -187,7 +187,7 @@ function Streamer() {
var __clickResetButton = function() {
wm.confirm("Are you sure you want to reset stream?").then(function (ok) {
if (ok) {
- var http = tools.makeRequest("POST", "/kvmd/streamer/reset", function() {
+ let http = tools.makeRequest("POST", "/kvmd/streamer/reset", function() {
if (http.readyState === 4) {
if (http.status !== 200) {
wm.error("Can't reset stream:<br>", http.responseText);
@@ -199,7 +199,7 @@ function Streamer() {
};
var __sendParam = function(name, value) {
- var http = tools.makeRequest("POST", `/kvmd/streamer/set_params?${name}=${value}`, function() {
+ let http = tools.makeRequest("POST", `/kvmd/streamer/set_params?${name}=${value}`, function() {
if (http.readyState === 4) {
if (http.status !== 200) {
wm.error("Can't configure stream:<br>", http.responseText);
@@ -209,23 +209,23 @@ function Streamer() {
};
var __resize = function(center=false) {
- var size = $("stream-size-slider").value;
+ let size = $("stream-size-slider").value;
$("stream-size-value").innerHTML = size + "%";
__size_factor = size / 100;
__applySizeFactor(center);
};
var __adjustSizeFactor = function() {
- var el_window = $("stream-window");
- var el_slider = $("stream-size-slider");
- var view = wm.getViewGeometry();
+ let el_window = $("stream-window");
+ let el_slider = $("stream-size-slider");
+ let view = wm.getViewGeometry();
- for (var size = 100; size >= el_slider.min; size -= el_slider.step) {
+ for (let size = 100; size >= el_slider.min; size -= el_slider.step) {
tools.info("Stream: adjusting size:", size);
$("stream-size-slider").value = size;
__resize(true);
- var rect = el_window.getBoundingClientRect();
+ let rect = el_window.getBoundingClientRect();
if (
rect.bottom <= view.bottom
&& rect.top >= view.top
@@ -238,7 +238,7 @@ function Streamer() {
};
var __applySizeFactor = function(center=false) {
- var el_stream_image = $("stream-image");
+ let el_stream_image = $("stream-image");
el_stream_image.style.width = __resolution.width * __size_factor + "px";
el_stream_image.style.height = __resolution.height * __size_factor + "px";
wm.showWindow($("stream-window"), false, center);