mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00
55 lines
1.2 KiB
HTML
55 lines
1.2 KiB
HTML
<meta charset="UTF-8">
|
|
<html>
|
|
<body>
|
|
<img src="libwebsockets.org-logo.png"><br>
|
|
|
|
Hello from the <b>minimal http Server Side Events example</b>.
|
|
<p>
|
|
This is a static page served from ./mount-origin/index.html.
|
|
<p>
|
|
It connects back to the server at <i>/sse/sourcename</i> using EventSource()<br>
|
|
and displays the perioding incoming event data below.
|
|
<p>
|
|
<textarea id=r readonly cols=40 rows=20></textarea><br>
|
|
</body>
|
|
<script>
|
|
|
|
var head = 0, tail = 0, ring = new Array();
|
|
|
|
es = new EventSource("/sse/sourcename");
|
|
try {
|
|
es.onopen = function() {
|
|
// console.log("EventSource opened");
|
|
document.getElementById("r").disabled = 0;
|
|
}
|
|
|
|
es.onmessage = function got_packet(msg) {
|
|
var n, s = "";
|
|
|
|
// console.log(msg.data);
|
|
ring[head] = msg.data + "\n";
|
|
head = (head + 1) % 50;
|
|
if (tail == head)
|
|
tail = (tail + 1) % 50;
|
|
|
|
n = tail;
|
|
do {
|
|
s = s + ring[n];
|
|
n = (n + 1) % 50;
|
|
} while (n != head);
|
|
|
|
document.getElementById("r").value = s;
|
|
document.getElementById("r").scrollTop =
|
|
document.getElementById("r").scrollHeight;
|
|
}
|
|
|
|
/* there is no onclose() for EventSource */
|
|
|
|
} catch(exception) {
|
|
alert('<p>Error' + exception);
|
|
}
|
|
|
|
</script>
|
|
|
|
</html>
|
|
|