-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp.html
75 lines (65 loc) · 3.07 KB
/
exp.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
<html>
<style>
html {
background-color: #444;
}
</style>
<body>
<div>
<span>X0 Pos: <em id="xposp0">-</em></span></br>
<span>Y0 Pos: <em id="yposp0">-</em></span></br>
<span>X1 Pos: <em id="xposp1">-</em></span></br>
<span>Y1 Pos: <em id="yposp1">-</em></span></br>
<span>X2 Pos: <em id="xposp2">-</em></span></br>
<span>Y2 Pos: <em id="yposp2">-</em></span></br>
<span>X3 Pos: <em id="xposp3">-</em></span></br>
<span>Y3 Pos: <em id="yposp3">-</em></span></br>
<span>X4 Pos: <em id="xposp4">-</em></span></br>
<span>Y4 Pos: <em id="yposp4">-</em></span></br>
<span>X5 Pos: <em id="xposp5">-</em></span></br>
<span>Y5 Pos: <em id="yposp5">-</em></span></br>
</div>
<svg style="position: absolute; top: 0px; left: 0px; border: none; height: 100vh; width: 100vw">
<circle id="circlep0" cx='0' cy='0' r="30" stroke="green" fill="red" />
<circle id="circlep1" cx='0' cy='0' r="30" stroke="red" fill="blue" />
<circle id="circlep2" cx='0' cy='0' r="30" stroke="yellow" fill="green" />
<circle id="circlep3" cx='0' cy='0' r="30" stroke="cyan" fill="white" />
<circle id="circlep4" cx='0' cy='0' r="30" stroke="green" fill="red" />
<circle id="circlep5" cx='0' cy='0' r="30" stroke="green" fill="red" />
</svg>
<script>
const coord = new URLSearchParams(window.location.search);
const screen_x = coord.getAll('x');
const screen_y = coord.getAll('y');
const canva_y = document.getElementsByTagName('svg')[0].clientHeight
const canva_x = document.getElementsByTagName('svg')[0].clientWidth
var ws = new WebSocket((window.location.protocol === 'https:' ? 'wss:' : 'ws:') + '//' + window.location.host);
// event emmited when connected
ws.onopen = function () {
console.log('websocket is connected ...')
// sending a send event to websocket server
ws.send('connected')
}
// event emmited when receiving message
ws.onmessage = function (ev) {
console.log("on message data", ev);
ts_mes = JSON.parse(ev.data);
pos = JSON.parse(ts_mes.message);
console.log("onmessage", pos)
for (var key in pos){
if (pos.hasOwnProperty(key)){
document.getElementById('xpos'+key).innerText = Math.round((pos[key].x - screen_x)*canva_x/1.105);
document.getElementById('ypos'+key).innerText = Math.round((screen_y - pos[key].y)*canva_y/0.633);
document.getElementById('circle'+key).setAttribute('cx', Math.round((pos[key].x - screen_x)*canva_x/1.105));
document.getElementById('circle'+key).setAttribute('cy', Math.round((screen_y - pos[key].y)*canva_y/0.633));
}
}
console.log(pos.x)
// document.getElementById('zpos').innerText = pos.z;
}
window.test = function (str) {
ws.send(str)
}
</script>
</body>
</html>