simple counting http server-side-events stream

This commit is contained in:
2020-04-07 22:16:53 -07:00
parent 0ba4f46c20
commit 83232ad888
5 changed files with 109 additions and 4 deletions

25
static/game.html Normal file
View 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>