fix(core): update

This commit is contained in:
2023-06-10 13:46:58 +02:00
parent 340a5c3fb7
commit 9552cb9de6
17 changed files with 4719 additions and 8429 deletions

View File

@@ -1,15 +1,20 @@
import * as plugins from './webdetector.plugins';
import * as plugins from './webdetector.plugins.js';
import {throttleTime } from 'rxjs/operators';
import { Platform } from './webdetector.classes.platform.js';
export interface IWebDetectorOptions {
checkOnlineUrl: string;
}
export class WebDetector {
// subclasses
public platform = new Platform();
options: IWebDetectorOptions;
private onlineObservableIntake = new plugins.smartrx.ObservableIntake();
onlineObservable = this.onlineObservableIntake.observable.pipe(throttleTime(10000));
public onlineObservable = this.onlineObservableIntake.observable.pipe(
plugins.smartrx.rxjs.ops.throttleTime(10000)
);
latestState: 'online' | 'offline' = 'online';
constructor(optionsArg: IWebDetectorOptions) {
@@ -17,7 +22,7 @@ export class WebDetector {
}
/**
*
*
*/
async isOnline() {
let reachesInternet: boolean = false;
@@ -27,20 +32,21 @@ export class WebDetector {
controller.abort();
}, 1000);
await fetchPromise.then(async response => {
reachesInternet = true
}).catch(err => {
// console.log(`request to ${this.options.checkOnlineUrl} failed}`)
});
await fetchPromise
.then(async (response) => {
reachesInternet = true;
})
.catch((err) => {
// console.log(`request to ${this.options.checkOnlineUrl} failed}`)
});
const latestLocalState = (() => {
if(reachesInternet) {
return 'online'
if (reachesInternet) {
return 'online';
} else {
return 'offline'
return 'offline';
}
})();
if(latestLocalState !== this.latestState) {
if (latestLocalState !== this.latestState) {
this.onlineObservableIntake.push(this.latestState);
}
this.latestState = latestLocalState;
@@ -53,4 +59,4 @@ export class WebDetector {
await plugins.smartdelay.delayFor(3000);
}
}
}
}