fix
This commit is contained in:
parent
0435a38e00
commit
3409fb8ab8
1 changed files with 8 additions and 3 deletions
|
|
@ -8,19 +8,24 @@ export class ConnectivityCheck extends Readable {
|
||||||
super()
|
super()
|
||||||
this.opts = opts
|
this.opts = opts
|
||||||
this.retryInterval = opts.retryInterval || 2000
|
this.retryInterval = opts.retryInterval || 2000
|
||||||
this._action({ internet: false })
|
this._lastState = { internet: false }
|
||||||
|
this._action(this._lastState)
|
||||||
this._update()
|
this._update()
|
||||||
}
|
}
|
||||||
|
|
||||||
async _update () {
|
async _update () {
|
||||||
|
let nextState
|
||||||
try {
|
try {
|
||||||
const hasInternet = await isOnline(this.opts)
|
const hasInternet = await isOnline(this.opts)
|
||||||
this._action({ internet: hasInternet })
|
nextState = { internet: hasInternet }
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._action({ internet: false })
|
nextState = { internet: hasInternet }
|
||||||
} finally {
|
} finally {
|
||||||
this._timeout = setTimeout(() => this._update(), this.retryInterval)
|
this._timeout = setTimeout(() => this._update(), this.retryInterval)
|
||||||
}
|
}
|
||||||
|
nextState.changed = nextState.internet !== this._lastState.internet
|
||||||
|
this._action(nextState)
|
||||||
|
this._lastState = nextState
|
||||||
}
|
}
|
||||||
|
|
||||||
_destroy () {
|
_destroy () {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue