-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
86 lines (61 loc) · 1.79 KB
/
index.html
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<html>
<head></head>
<body>
<script type="text/javascript">
var sock = null;
var canv = null;
var wsurl = "ws://127.0.0.1:80/ws";
function getMousePos(canvas, evt) {
var rect = canvas.getBoundingClientRect();
return {
x: evt.clientX - rect.left,
y: evt.clientY - rect.top
};
};
window.onload = function() {
canv = document.getElementById("theCanvas");
var ctx = canv.getContext("2d");
console.log("onload");
sock = new WebSocket(wsurl);
sock.onopen = function() {
console.log("connected to " + wsurl);
}
sock.onclose = function(e) {
console.log("connection closed (" + e.code + ")");
}
sock.onmessage = function(e) {
var img=new Image();
img.src=e.data;
ctx.drawImage(img,0,0);
}
canv.onmousedown= function(e) {
e.preventDefault();
sock.send('mlbtn1');
return false;
};
canv.onmouseup= function(e) {
e.preventDefault();
sock.send('mlbtn0');
return false;
};
canv.onmousemove= function(e) {
e.preventDefault();
var mouse = getMousePos(canv,e);
sock.send('mx'+mouse.x+'my'+mouse.y);
return false;
};
window.onkeydown= function(e) {
e.preventDefault();
sock.send('kdn'+e.keyCode);
return false;
};
window.onkeyup= function(e) {
e.preventDefault();
sock.send('kup'+e.keyCode);
return false;
};
};
</script>
<canvas id="theCanvas" width="800" height="600"></canvas>
</body>
</html>