abort events, polling instead

This commit is contained in:
Torsten Ruger
2021-07-02 23:20:42 +03:00
parent 3fad0f86f6
commit 1785f07706
6 changed files with 35 additions and 63 deletions

View File

@ -15,6 +15,8 @@
<div class="ct-chart chart1"></div>
<h1> Monthly </h1>
<div class="ct-chart chart2"></div>
<h1> Log </h1>
<div id="log"></div>
<script >
var chart;
function load_chart( url , clazz ){
@ -34,27 +36,22 @@
load_chart("/weekly" , ".chart1");
load_chart("/monthly" , ".chart2");
}
if (!!window.EventSource) {
var source = new EventSource('/events');
var log = document.getElementById("log")
source.addEventListener('open', function(e) {
console.log("Events Connected");
}, false);
source.addEventListener('error', function(e) {
if (e.target.readyState != EventSource.OPEN) {
console.log("Events Disconnected");
function myCallback() {
function get_log( ){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
log.innerHTML += this.responseText;
}
}
}, false);
source.addEventListener('message', function(e) {
console.log("message", e.data);
}, false);
source.addEventListener('myevent', function(e) {
console.log("myevent", e.data);
}, false);
xhttp.open("GET", "/log", true);
xhttp.send();
};
}
var intervalID = window.setInterval(get_log, 1500);
</script>
<script onload="load_charts();" src="/chartist.min.js.gz"> </script>