From 3409fb8ab8cf666de1c29b6eb232a958263cb591 Mon Sep 17 00:00:00 2001 From: rdl technix Date: Fri, 3 Sep 2021 19:08:30 +0200 Subject: [PATCH] fix --- backend/lib/is-online.mjs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/lib/is-online.mjs b/backend/lib/is-online.mjs index 5218179..5d46cdc 100644 --- a/backend/lib/is-online.mjs +++ b/backend/lib/is-online.mjs @@ -8,19 +8,24 @@ export class ConnectivityCheck extends Readable { super() this.opts = opts this.retryInterval = opts.retryInterval || 2000 - this._action({ internet: false }) + this._lastState = { internet: false } + this._action(this._lastState) this._update() } async _update () { + let nextState try { const hasInternet = await isOnline(this.opts) - this._action({ internet: hasInternet }) + nextState = { internet: hasInternet } } catch (err) { - this._action({ internet: false }) + nextState = { internet: hasInternet } } finally { this._timeout = setTimeout(() => this._update(), this.retryInterval) } + nextState.changed = nextState.internet !== this._lastState.internet + this._action(nextState) + this._lastState = nextState } _destroy () {