add .html files for SSE and websocket examples

This commit is contained in:
Simon Cruanes 2024-03-12 10:39:50 -04:00
parent fe9596f4fe
commit 78ded146ac
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 46 additions and 0 deletions

21
examples/sse_demo.html Normal file
View file

@ -0,0 +1,21 @@
<!-- to be used with sse_server -p 8087 -->
<html>
<head>
<script src="https://unpkg.com/htmx.org@1.7.0"></script>
<script>
htmx.createEventSource = (url) => {
return new EventSource(url, {withCredentials:false});
}
</script>
</head>
<body hx-trigger="onload" hx-sse="connect:http://localhost:8087/clock">
<p>time:</p>
<div hx-sse="swap:tick" hx-swap="innerHtml"> </div>
<!-- <div hx-trigger="sse:tick" hx-get="/news"></div> -->
</body>
</html>

25
examples/ws_demo.html Normal file
View file

@ -0,0 +1,25 @@
<!-- to be used with echo_ws -p 8085 -->
<html>
<head>
<script>
console.log('hello')
const ws = new WebSocket('ws://localhost:8085/echo');
ws.onmessage = (msg) => console.log(`received: ${msg}`);
let count = 0;
setInterval(() => {
const msg = `hello ${count++}`;
console.log(`send ${msg}`);
ws.send(msg);
}, 2000);
</script>
</head>
<body>
open console!
</body>
</html>