This repository was archived by the owner on Nov 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.html
222 lines (163 loc) · 5.76 KB
/
controller.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<html>
<style>
</style>
<head>
<script>
var ws = new WebSocket("ws://localhost:3000/");
let orientation = "";
let name = "";
let moves = document.getElementById('moves');
var height = window.innerHeight;
let y_current = 0;
let y_last = 0;
let touch = false;
//var document = document.querySelector('.document');
function game() {
if (y_current > y_last && touch) { //changes orientation relativ
document.getElementById("text1").innerHTML = "down";
ws.send(JSON.stringify({
id: "GAME",
name: name,
orien: orientation,
y: "down"
}));
} else if (y_current < y_last && touch) {
document.getElementById("text1").innerHTML = "up";
ws.send(JSON.stringify({
id: "GAME",
name: name,
orien: orientation,
y: "up"
}));
} else if (touch == false || y_last==y_current) {
document.getElementById("text1").innerHTML = "";
}
y_last = y_current;
/* if (y_current > height / 2 && touch) { //changes orientation in the mid
document.getElementById("text1").innerHTML = "down";
ws.send(JSON.stringify({
id: "GAME",
name: name,
orien: orientation,
y: "down"
}));
} else if (y_current < height / 2 && touch) {
document.getElementById("text1").innerHTML = "up";
ws.send(JSON.stringify({
id: "GAME",
name: name,
orien: orientation,
y: "up"
}));
}*/
}
function load() {
document.getElementById("text1").innerHTML = "Enter the Code from the Display device";
document.getElementById("text2").innerHTML = "Select your orientation from the Display device";
if ("WebSocket" in window) {
//alert("WebSocket is supported by your Browser!");
// Let us open a web socket
ws.onopen = function() {
console.log("Connected");
// Web Socket is connected, send data using send()
//alert("Message is sent...");
};
ws.onmessage = function(evt) {
let data = evt.data;
console.log(data);
var obj = JSON.parse(data);
switch (obj.id) {
case "CONTROLLER":
if (obj.orien == orientation) {
alert("anmeldung erfolgreich");
} else if (obj.orien == "nothing") {
alert("false Display Code or Room is full !! Try it again please");
} else {
if (orientation == "_left") {
alert("You are now Right! The other Player was faster");
} else {
alert("You are now Left! The other Player was faster");
}
}
break;
case "GO":
document.getElementById('id').style.display = "none";
document.getElementById('text2').style.display = "none";
document.getElementById('right').style.display = "none";
document.getElementById("left").style.display = "none";
document.getElementById('login').style.display = "none";
window.addEventListener('touchstart', function(eve) {
var touchobj = eve.changedTouches[0]; // erster Finger
eve.preventDefault();
touch = true;
});
window.addEventListener('touchmove', function(eve) {
var touchobj = eve.changedTouches[0]; // erster Finger
y_current = parseInt(touchobj.clientY, 10);
eve.preventDefault();
});
window.addEventListener('touchend', function(eve) {
var touchobj = eve.changedTouches[0]; // reference first touch point for this event
eve.preventDefault();
touch = false;
});
setInterval(game, 100 / 120);
break;
} //swith
}
ws.onclose = function() {
// websocket is closed.
console.log("connection ends");
};
} else {
// The browser doesn't support WebSocket
alert("WebSocket NOT supported by your Browser!");
}
}
function login() {
name = document.getElementById('id').value;
if (name == "") {
alert("Enter Id");
}
if (orientation === "") {
alert("Choos an orientation");
} else {
ws.send(JSON.stringify({
id: "CONTROLLER",
name: name,
orien: orientation
}));
console.log(name);
}
}
function to_name() {
let to = document.getElementById('to').value;
let message = document.getElementById('message').value;
ws.send(JSON.stringify({
id: "SEND_TO",
to_name: to,
msg: message
}));
console.log(JSON.stringify({
to_name: to,
msg: message
}));
}
function right() {
orientation = "_right";
}
function left() {
orientation = "_left";
}
</script>
</head>
<body onload="load();">
<p><span id="text1" style="display:inline-block"></span></p>
<input type="text" style="display:inline-block" value="" id="id" /><!-- Username -->
<p><span id="text2" style="display:inline-block"></span></p>
<input type="button" style="display:inline-block" value="Right Controller" onclick="right();" id="right" /> <!-- Controller -->
<input type="button" style="display:inline-block" value="Left Controller" onclick="left();" id="left" /><!-- Display -->
<p id="p2"></p>
<input type="button" style="display:inline-block" value="Login as Controller" onclick="login();" id="login" />
</body>
</html>