mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-04 02:49:42 +03:00
webdojo: attempt reconnecting only after success
Instead of always endlessly trying even if the endpoint was never acknowledged.
This commit is contained in:
parent
b12f89228b
commit
f9e6c9f913
@ -19,9 +19,11 @@ export default class Subscription {
|
|||||||
|
|
||||||
setupSlog() {
|
setupSlog() {
|
||||||
const slog = new EventSource('/~/slog', { withCredentials: true });
|
const slog = new EventSource('/~/slog', { withCredentials: true });
|
||||||
|
let available = false;
|
||||||
|
|
||||||
slog.onopen = e => {
|
slog.onopen = e => {
|
||||||
console.log('slog: opened stream');
|
console.log('slog: opened stream');
|
||||||
|
available = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.onmessage = e => {
|
slog.onmessage = e => {
|
||||||
@ -30,11 +32,13 @@ export default class Subscription {
|
|||||||
|
|
||||||
slog.onerror = e => {
|
slog.onerror = e => {
|
||||||
console.error('slog: eventsource error:', e);
|
console.error('slog: eventsource error:', e);
|
||||||
window.setTimeout(() => {
|
if (available) {
|
||||||
if (slog.readyState !== EventSource.CLOSED) return;
|
window.setTimeout(() => {
|
||||||
console.log('slog: reconnecting...');
|
if (slog.readyState !== EventSource.CLOSED) return;
|
||||||
this.setupSlog();
|
console.log('slog: reconnecting...');
|
||||||
}, 10000);
|
this.setupSlog();
|
||||||
|
}, 10000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user