-
Notifications
You must be signed in to change notification settings - Fork 0
/
testClient2.html
39 lines (35 loc) · 991 Bytes
/
testClient2.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
<html>
<script>
let websocket = new WebSocket('ws://192.168.0.178:3000');
const maxLat = 5;
const maxLong = 5;
// Calculate a minute of latitude/longitude
const minuteLat = 1 / (maxLat * 10);
const minuteLong = 1 / (maxLong * 10);
let lat = 39.7684;
let long = -86.1581;
websocket.onopen = () => {
// connection opened
console.log('connected to server');
websocket.send(JSON.stringify({
method: 'publish',
locationID: '2',
}));
setInterval(() => {
// Send to Client
console.log('sending');
websocket.send(JSON.stringify({
method: 'emitLocation',
location: {
latitude: lat,
longitude: long,
},
locationID: '2'
}));
//Update latitude and longitude up to a minute increment
lat += Math.random() * minuteLat * (Math.random() < 0.5 ? -1 : 1);
long += Math.random() * minuteLong * (Math.random() < 0.5 ? -1 : 1);
}, 3000);
};
</script>
</html>