distributor/public/index.html
2025-04-15 18:15:02 -06:00

35 lines
1 KiB
HTML

<!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>
<div id="stuff"></div>
<script>
const socket = new WebSocket(`ws://${window.location.host}/iem`);
socket.onopen = () => {
const newDiv = document.createElement('div');
newDiv.innerText = "WebSocket connection opened";
document.getElementById('stuff').prepend(newDiv);
};
socket.onclose = () => {
const newDiv = document.createElement('div');
newDiv.innerText = "WebSocket connection closed";
document.getElementById('stuff').prepend(newDiv);
};
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
const explanation = `Event: ${JSON.stringify(data.event)}, Channel: ${JSON.stringify(data.channel)}, Station: ${data.station}`;
console.log(explanation);
const newDiv = document.createElement('div');
newDiv.innerText = explanation;
document.getElementById('stuff').prepend(newDiv);
};
</script>
</body>
</html>