summaryrefslogtreecommitdiff
path: root/kvmd/web/js/hid.js
blob: 3d0ed9612cea52a3ec94a548ffc6d69e658c7013 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var hid = new function() {
	var __install_timer = null;

	this.installCapture = function(ws) {
		var http = tools.makeRequest("GET", "/kvmd/hid", function() {
			if (http.readyState === 4) {
				if (http.status === 200) {
					features = JSON.parse(http.responseText).result.features;
					if (features.mouse) {
						mouse.installCapture(ws);
					}
					keyboard.installCapture(ws);
				} else {
					tools.error("Can't resolve HID features:", http.responseText);
					__install_timer = setTimeout(() => hid.installCapture(ws), 1000);
				}
			}
		});
	};

	this.clearCapture = function() {
		if (__install_timer) {
			clearTimeout(__install_timer);
			__install_timer = null;
		}
		mouse.clearCapture();
		keyboard.clearCapture();
	};
}