basic SSE example, Web client
This commit is contained in:
29
examples/events.html
Normal file
29
examples/events.html
Normal file
@@ -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>
|
||||
Reference in New Issue
Block a user