-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
36 lines (34 loc) · 1.13 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Gravity Simulator</title>
<link rel="stylesheet" href="styles.css"/>
</head>
<body>
<div class="bg">
<div class="textbox"><div class="moontext">LOADING...</div></div>
<script>
function connect() {
var ws = new WebSocket("ws://127.0.0.1:5678/");
console.log("Connecting websocket")
ws.onmessage = function (event) {
var obj = JSON.parse(event.data);
document.getElementsByClassName('moontext')[0].innerHTML = obj['Moon'] + ' kg';
console.log("receiving" + obj['Moon'])
};
ws.onclose = function(e) {
console.log('socket closed try again');
setTimeout(function() {
connect();
}, 1000);
}
ws.onerror = function(err) {
console.error(err)
};
};
connect();
</script>
</div>
</body>
</html>