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

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/webdetector',
version: '1.0.6',
description: 'detect different environments within the browser'
}

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);
}
}
}
}

View File

@ -0,0 +1,25 @@
export type TWebPlatform = 'android' | 'ios' | 'windows' | 'mac' | 'linux' | 'unknown';
export class Platform {
public detectPlatform(): TWebPlatform {
const userAgent = navigator?.userAgent?.toLowerCase();
if (!userAgent) {
return 'unknown';
}
if (/android/.test(userAgent)) {
return 'android';
} else if (/iphone|ipad|ipod/.test(userAgent)) {
return 'ios';
} else if (/win/.test(userAgent)) {
return 'windows';
} else if (/mac/.test(userAgent)) {
return 'mac';
} else if (/linux/.test(userAgent)) {
return 'linux';
}
return 'unknown';
}
}

View File

@ -1,7 +1,4 @@
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartrx from '@pushrocks/smartrx';
export {
smartdelay,
smartrx
}
export { smartdelay, smartrx };