webdojo: attempt reconnecting only after success
Instead of always endlessly trying even if the endpoint was never
acknowledged.
@@ -19,9 +19,11 @@ export default class Subscription {
setupSlog() {
const slog = new EventSource('/~/slog', { withCredentials: true });
+ let available = false;
slog.onopen = e => {
console.log('slog: opened stream');
+ available = true;
}
slog.onmessage = e => {
@@ -30,6 +32,7 @@ export default class Subscription {
slog.onerror = e => {
console.error('slog: eventsource error:', e);
+ if (available) {
window.setTimeout(() => {
if (slog.readyState !== EventSource.CLOSED) return;
console.log('slog: reconnecting...');
@@ -37,6 +40,7 @@ export default class Subscription {
}, 10000);
}
}
+ }
delete() {
this.channel.delete();
