diff --git a/hostmonitor b/hostmonitor index 9f93064..6ee5651 100755 Binary files a/hostmonitor and b/hostmonitor differ diff --git a/web/client/src/stream.ts b/web/client/src/stream.ts index a0cc3c1..83f7380 100644 --- a/web/client/src/stream.ts +++ b/web/client/src/stream.ts @@ -1,9 +1,10 @@ -import { map, Observable, scan } from 'rxjs' +import { fromEvent, map, mergeMap, Observable, retryWhen, scan, take, timer } from 'rxjs' import { WebSocketSubject } from 'rxjs/webSocket' export type Stream = Observable export namespace Stream { + const RETRY_DELAY = 5000 export interface Item { id: string inProgress: boolean @@ -14,6 +15,18 @@ export namespace Stream { export const create = () => { const sock = new WebSocketSubject(`ws://${location.host}/ws`) return sock.pipe( + retryWhen(errors => + errors.pipe( + mergeMap(() => { + if (window.navigator.onLine) { + console.warn(`Retrying in ${RETRY_DELAY}ms.`) + return timer(RETRY_DELAY) + } else { + return fromEvent(window, 'online').pipe(take(1)) + } + }) + ) + ), scan>( (a, c) => (a.set(c.id, c), a), new Map()