41 lines
1.2 KiB
Plaintext
41 lines
1.2 KiB
Plaintext
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Blab</title>
|
|
</head>
|
|
|
|
<body>
|
|
<h1>Hello, world!</h1>
|
|
<p id="iteration">Iteration: {{ iteration }} messages 0.<p>
|
|
<ul id="objects">
|
|
{% for object in objects %}
|
|
<li id="object-{{ object.id }}">{{ object.name }} @ {{ object.x }}, {{ object.y }}</li>
|
|
{% endfor %}
|
|
</ul>
|
|
|
|
|
|
<script>
|
|
ws = new WebSocket("ws://localhost:3030/state");
|
|
|
|
ws.onopen = function() {
|
|
console.log("Connected");
|
|
ws.send("MOAR");
|
|
}
|
|
let messages = 0;
|
|
|
|
ws.onmessage = function(e) {
|
|
const data = JSON.parse(e.data);
|
|
messages += 1;
|
|
|
|
document.getElementById("iteration").innerText = `Iteration: ${data.iteration} messages ${messages}.`;
|
|
for (n in data.objects) {
|
|
const ob = data.objects[n];
|
|
const li = document.getElementById(`object-${ob.id}`);
|
|
li.innerText = `${ob.name} @ ${ob.x}, ${ob.y}`;
|
|
}
|
|
ws.send("MOAR");
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|