simple counting http server-side-events stream
This commit is contained in:
25
static/game.html
Normal file
25
static/game.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Wabi Spectrum</title>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<section id="log">
|
||||
<h1>Incoming Events</h1>
|
||||
</section>
|
||||
<template id="logline">
|
||||
<p>Count updated: <span></span>
|
||||
</template>
|
||||
<script>
|
||||
"use strict";
|
||||
let sse = new EventSource('events');
|
||||
sse.addEventListener('count', msg => {
|
||||
const template = document.querySelector('#logline').content.cloneNode(true);
|
||||
template.querySelector('span').textContent = msg.data;
|
||||
document.querySelector('#log').appendChild(template);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user