Skip to content

Commit

Permalink
add .html files for SSE and websocket examples
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Mar 12, 2024
1 parent fe9596f commit 78ded14
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
21 changes: 21 additions & 0 deletions examples/sse_demo.html
Original file line number Diff line number Diff line change
@@ -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 changes: 25 additions & 0 deletions examples/ws_demo.html
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 78ded14

Please sign in to comment.