-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathws-client.html
More file actions
68 lines (57 loc) · 1.99 KB
/
ws-client.html
File metadata and controls
68 lines (57 loc) · 1.99 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
<script>
var wsServer = 'wss://ws-tracking.pulsestracker.com';
var websocket = new WebSocket(wsServer);
const appId = '542bb636-1535-4523-a17e-8eac5721ff2a';
const clientId = '13946096-58b7-42d8-8a46-d239b276568e';
websocket.onopen = function (evt) {
console.log("Connected to WebSocket server.");
// Send location every 2 seconds
setInterval(() => {
if (websocket.readyState === WebSocket.OPEN) {
navigator.geolocation.getCurrentPosition((position) => {
console.log(position);
const locationData = {
appId: appId,
clientId: clientId,
data: {
type: "Point",
coordinates: [position.coords.longitude, position.coords.latitude]
},
extra: {
key: "value"
}
};
// Send location data as JSON
websocket.send(JSON.stringify(locationData));
console.log('Location sent:', locationData);
}, (error) => {
console.error('Error getting location:', error);
});
}
}, 3000); // Every 2 seconds
};
websocket.onclose = function (evt) {
console.log("Disconnected");
};
websocket.onmessage = function (evt) {
if (event.data === 'Pong') {
console.log('Received Pong from server');
} else {
// Handle other messages
console.log('Received:', event.data);
}
};
websocket.onerror = function (evt, e) {
console.log('Error occurred: ' + evt.data);
};
</script>
</html>