summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2021-09-20 07:15:56 +0300
committerMaxim Devaev <[email protected]>2021-09-20 07:15:56 +0300
commit8ab9c8f07bebf9e9e23b9cb057d9e143bad7e10b (patch)
treed6d0862a37c28c081b803d82e29d65346842c192
parent701df3c76fff0679c6b1b05c067fe05c3b9f5e38 (diff)
record atx actions
-rw-r--r--web/kvm/index.html2
-rw-r--r--web/kvm/navbar-macro.pug2
-rw-r--r--web/share/js/kvm/atx.js3
-rw-r--r--web/share/js/kvm/recorder.js24
-rw-r--r--web/share/js/kvm/session.js2
5 files changed, 29 insertions, 4 deletions
diff --git a/web/kvm/index.html b/web/kvm/index.html
index 7d6a097f..1b89ed6a 100644
--- a/web/kvm/index.html
+++ b/web/kvm/index.html
@@ -437,7 +437,7 @@
</li>
<li class="right"><a class="menu-button" href="#"><img class="led-gray" data-dont-hide-menu id="hid-recorder-led" src="/share/svg/led-gear.svg">Macro</a>
<div class="menu" data-dont-hide-menu>
- <div class="text"><b>Record and play HID/GPIO actions<br></b><sub>For security reasons, the record will not be saved on the PiKVM</sub></div>
+ <div class="text"><b>Record and play HID/ATX/GPIO actions<br></b><sub>For security reasons, the record will not be saved on the PiKVM</sub></div>
<hr>
<div class="buttons buttons-row">
<button class="row25" disabled data-force-hide-menu id="hid-recorder-record">&bull; Rec</button>
diff --git a/web/kvm/navbar-macro.pug b/web/kvm/navbar-macro.pug
index 8880550d..47db1fe1 100644
--- a/web/kvm/navbar-macro.pug
+++ b/web/kvm/navbar-macro.pug
@@ -4,7 +4,7 @@ li(class="right")
| Macro
div(data-dont-hide-menu class="menu")
div(class="text")
- b Record and play HID/GPIO actions#[br]
+ b Record and play HID/ATX/GPIO actions#[br]
sub For security reasons, the record will not be saved on the PiKVM
hr
div(class="buttons buttons-row")
diff --git a/web/share/js/kvm/atx.js b/web/share/js/kvm/atx.js
index 3c0bf6c0..66a2cb4e 100644
--- a/web/share/js/kvm/atx.js
+++ b/web/share/js/kvm/atx.js
@@ -27,7 +27,7 @@ import {tools, $} from "../tools.js";
import {wm} from "../wm.js";
-export function Atx() {
+export function Atx(__recorder) {
var self = this;
/************************************************************************/
@@ -82,6 +82,7 @@ export function Atx() {
}
}
});
+ __recorder.recordAtxButtonEvent(button);
};
if ($("atx-ask-switch").checked) {
diff --git a/web/share/js/kvm/recorder.js b/web/share/js/kvm/recorder.js
index f2ca6d5c..93def77d 100644
--- a/web/share/js/kvm/recorder.js
+++ b/web/share/js/kvm/recorder.js
@@ -71,6 +71,10 @@ export function Recorder() {
__recordEvent({"event_type": "print", "event": {"text": text}});
};
+ self.recordAtxButtonEvent = function(button) {
+ __recordEvent({"event_type": "atx_button", "event": {"button": button}});
+ };
+
self.recordGpioSwitchEvent = function(channel, to) {
__recordEvent({"event_type": "gpio_switch", "event": {"channel": channel, "state": to}});
};
@@ -171,6 +175,8 @@ export function Recorder() {
__checkType(event.event.delta, "object", "Non-object mouse wheel delta");
__checkInt(event.event.delta.x, "Non-int mouse delta X");
__checkInt(event.event.delta.y, "Non-int mouse delta Y");
+ } else if (event.event_type === "atx_button") {
+ __checkType(event.event.button, "string", "Non-string ATX button");
} else if (event.event_type === "gpio_switch") {
__checkType(event.event.channel, "string", "Non-string GPIO channel");
__checkType(event.event.state, "boolean", "Non-bool GPIO state");
@@ -212,9 +218,11 @@ export function Recorder() {
while (index < __events.length) {
__setCounters(__events.length - index + 1, __events_time - time);
let event = __events[index];
+
if (event.event_type === "delay") {
__play_timer = setTimeout(() => __runEvents(index + 1, time + event.event.millis), event.event.millis);
return;
+
} else if (event.event_type === "print") {
let http = tools.makeRequest("POST", "/api/hid/print?limit=0", function() {
if (http.readyState === 4) {
@@ -230,6 +238,20 @@ export function Recorder() {
}
}, event.event.text, "text/plain");
return;
+
+ } else if (event.event_type === "atx_button") {
+ let http = tools.makeRequest("POST", `/api/atx/click?button=${event.event.button}`, function() {
+ if (http.readyState === 4) {
+ if (http.status !== 200) {
+ wm.error("ATX error:<br>", http.responseText);
+ __stopProcess();
+ } else if (http.status === 200) {
+ __play_timer = setTimeout(() => __runEvents(index + 1, time), 0);
+ }
+ }
+ });
+ return;
+
} else if (["gpio_switch", "gpio_pulse"].includes(event.event_type)) {
let path = "/api/gpio";
if (event.event_type === "gpio_switch") {
@@ -248,9 +270,11 @@ export function Recorder() {
}
});
return;
+
} else if (["key", "mouse_button", "mouse_move", "mouse_wheel"].includes(event.event_type)) {
__ws.send(JSON.stringify(event));
}
+
index += 1;
}
if ($("hid-recorder-loop-switch").checked) {
diff --git a/web/share/js/kvm/session.js b/web/share/js/kvm/session.js
index 3b2f18c1..e5f21ef1 100644
--- a/web/share/js/kvm/session.js
+++ b/web/share/js/kvm/session.js
@@ -47,7 +47,7 @@ export function Session() {
var __streamer = new Streamer();
var __recorder = new Recorder();
var __hid = new Hid(__streamer.getResolution, __recorder);
- var __atx = new Atx();
+ var __atx = new Atx(__recorder);
var __msd = new Msd();
var __gpio = new Gpio(__recorder);