-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
135 lines (124 loc) · 2.98 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html>
<head>
<title>Trackpad</title>
<style>
body {
width: 100vw;
height: 100vh;
display: flex;
flex-wrap: wrap;
margin: 0px;
background: black;
padding: 0px;
}
body > * {
flex-grow: 1;
width:200px;
}
.holder {
display: flex;
justify-content: center;
flex-wrap: wrap;
align-items: stretch;
}
.holder * {
flex-grow:1;
}
.holder input {
text-align: center;
border: none;
padding: 0px;
flex: 0 0 100%;
}
.holder div {
background: #333;
margin: 1px;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
var canvas = document.createElement("div");
var leftButton = document.createElement("div");
leftButton.addEventListener("touchstart",() => {
socket.emit("ldown");
})
leftButton.addEventListener("touchend",()=> {
socket.emit("lup");
})
var rightButton = document.createElement("div");
rightButton.addEventListener("touchstart",() => {
socket.emit("rdown");
})
rightButton.addEventListener("touchend",() => {
socket.emit("rup");
})
var textInput = document.createElement("input");
textInput.setAttribute("type","text");
textInput.addEventListener("keyup",event => {
var key = textInput.value;
switch(event.keyCode) {
case 13:
key = "enter";
break;
case 8:
key = "backspace";
}
socket.emit("key",key);
textInput.value ="";
})
var holder = document.createElement("div");
holder.className = "holder";
holder.appendChild(textInput);
holder.appendChild(leftButton);
holder.appendChild(rightButton);
var currentPos = {};
var mouseIndex = 0;
var moved = false;
var li;
canvas.addEventListener("touchstart",event => {
moved = false;
mouseIndex = event.touches.length - 1;
li = setTimeout(() => {
socket.emit("ldown");
},200)
event.preventDefault();
event.stopPropagation();
currentPos.x = event.touches[mouseIndex].clientX;
currentPos.y = event.touches[mouseIndex].clientY;
socket.emit("start");
})
canvas.addEventListener("touchmove", event => {
event.preventDefault();
event.stopPropagation();
if(Math.abs(event.touches[mouseIndex].clientX - currentPos.x) > 1 ||
Math.abs(event.touches[mouseIndex].clientY - currentPos.y) > 1) {
if(!moved) moved = true;
}
if(moved) clearTimeout(li);
socket.emit("move",{
x: (event.touches[mouseIndex].clientX - currentPos.x) * 2,
y: (event.touches[mouseIndex].clientY - currentPos.y) * 2
})
})
canvas.addEventListener("touchend", event => {
if(!moved) {
socket.emit("ldown");
}
socket.emit("lup");
clearTimeout(li);
lastUp = Date.now();
})
socket.on("s",data => {
console.log("ata:image/bmp;base64," + data + "")
//canvas.style.backgroundImage = "url(data:image/bmp;base64," + data + ")"
})
document.body.appendChild(holder);
document.body.appendChild(canvas);
</script>
</body>
</html>