You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
793 B
28 lines
793 B
1 year ago
|
<script type="text/javascript">
|
||
|
const ws = new WebSocket(`ws://${location.host}/ws`);
|
||
|
|
||
|
ws.addEventListener('message', function (event) {
|
||
|
const li = document.createElement("li");
|
||
|
li.appendChild(document.createTextNode(event.data));
|
||
|
document.getElementById("messages").appendChild(li);
|
||
|
});
|
||
|
|
||
|
function send(event) {
|
||
|
const message = (new FormData(event.target)).get("message");
|
||
|
if (message) {
|
||
|
ws.send(message);
|
||
|
}
|
||
|
event.target.reset();
|
||
|
return false;
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<div style="display: flex; height: 100%; flex-direction: column">
|
||
|
<ul id="messages" style="flex-grow: 1; list-style-type: none"></ul>
|
||
|
|
||
|
<form onsubmit="return send(event)">
|
||
|
<input type="text" name="message" minlength="1" />
|
||
|
<button type="submit">Send</button>
|
||
|
</form>
|
||
|
</div>
|