I\'m working on a project utilizing Server-Sent-Events and have just run into something interesting: connection loss is handled differently between Chrome and Firefox.
O
here's another variation folks might like
let events = null;
function connect() {
events = new EventSource("/some/url");
events.onerror = function() {
events.close();
}
}
connect();
let reconnecting = false;
setInterval(() => {
if (events.readyState == EventSource.CLOSED) {
reconnecting = true;
console.log("reconnecting...");
connect();
} else if (reconnecting) {
reconnecting = false
console.log("reconnected!");
}
}, 3000);