src/murja-newui/test_ws.html
<html>
<body>
<textarea id="msgs"></textarea>
<br />
<button id="send">Send stuff </button>
<script>
window.addEventListener('DOMContentLoaded', _ => {
const socket = new WebSocket("http://localhost:12345/newui");
const msgs = document.querySelector('#msgs');
const sendbtn = document.querySelector('#send');
// Connection opened
socket.addEventListener("open", (event) => {
msgs.value += event;
msgs.value += "\n";
});
// Listen for messages
socket.addEventListener("message", (event) => {
msgs.value += event.data + "\n";
});
sendbtn.addEventListener('click', _ => {
socket.send('Aslan on hassu kissa');
});
});
</script>
</body>
</html>