-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener.html
37 lines (32 loc) · 976 Bytes
/
listener.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
<!DOCTYPE html>
<html>
<head>
<title>WebSocket Relay Client</title>
</head>
<body>
<h1>WebSocket Relay Client</h1>
<pre id="timestamp"></pre>
<pre id="data"></pre>
<script>
const ws = new WebSocket('ws://localhost:9082'); // Replace with your server URL
ws.onopen = () => {
console.log('Connected to WebSocket server.');
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
var currentdate = new Date();
var datetime = "Last Sync: " + currentdate.getDate() + "/"
+ (currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear() + " @ "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":"
+ currentdate.getSeconds();
document.getElementById('timestamp').innerText = datetime;
document.getElementById('data').innerText = JSON.stringify(data, null, 2);
};
ws.onclose = () => {
console.log('WebSocket connection closed.');
};
</script>
</body>
</html>