basic SSE example, Web client

master
Fabien Benetou 9 months ago
parent 3e7aa01e34
commit 2eedef5398
  1. 29
      examples/events.html

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="https://glitch.com/favicon.ico" />
<title>offtopus events</title>
</head>
<body>
<div id="content"></div>
<hr>
<div id="events"></div>
<script>
const source = new EventSource('/events');
source.addEventListener('message', message => {
console.log('Got', message);
// Display the event data in the `content` div
document.querySelector('#events').innerHTML = event.data;
})
</script>
</body>
</html>
Loading…
Cancel
Save