blob: cb61185a5fb0a2178000951d0358b10c492ecd79 (
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>π-kvm</title>
<style>
body {
text-align: center;
}
.screen, .screen * {
box-sizing: border-box;
}
.screen {
display: inline-block;
background-color: #e5e5f5;
font-family: Arial, Tahoma, Verdana, sans;
font-size: 10pt;
text-align: center;
padding: 1em;
text-align: left;
}
.screen .screen-image {
width: 720px;
height: 576px;
border: 1px solid #77d;
display: inline-block;
}
</style>
</head>
<script>
ws = new WebSocket("ws://" + location.host + "/kvmd/ws");
function onWsMessage(message) {
console.log(message.data);
/*if (message.data == "EVENT mjpg_streamer started") {
document.getElementById("stream-image").src = "/streamer/?action=stream&time=" + new Date().getTime();
}*/
}
function onKeyEvent(event, state) {
// TODO: run this code under the lock
console.log("Key", (state ? "pressed:" : "released:"), event)
ws.send(JSON.stringify({
event_type: "key_event",
key_code: event.code,
key_state: state,
}));
}
ws.onmessage = (message) => onWsMessage(message);
ws.onerror = (error) => console.error(error);
ws.onclose = () => console.log("closed");
// https://www.codeday.top/2017/05/03/24906.html
document.onkeydown = (event) => onKeyEvent(event, true);
document.onkeyup = (event) => onKeyEvent(event, false);
</script>
<body>
<div class="screen">
<img src="/streamer/?action=stream" id="stream-image" class="screen-image" alt="" />
</div>
</body>
</html>
|