Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
4d6ae3ba87 | |||
68ac5e6ec2 | |||
d4401172e6 | |||
1887645625 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/webdetector",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.2",
|
||||
"private": false,
|
||||
"description": "detect different environments within the browser",
|
||||
"main": "dist_ts/index.js",
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as webdetector from '../ts/index';
|
||||
import * as webdetector from '../ts/index.js';
|
||||
let testWebDetector: webdetector.WebDetector;
|
||||
|
||||
tap.test('first test', async () => {
|
||||
const testWebDetector = new webdetector.WebDetector({
|
||||
testWebDetector = new webdetector.WebDetector({
|
||||
checkOnlineUrl: 'https://pubapi.lossless.one',
|
||||
});
|
||||
|
||||
@ -19,6 +19,12 @@ tap.test('should be online', async () => {
|
||||
testWebDetector.onlineObservable.subscribe((state) => {
|
||||
console.log(state);
|
||||
});
|
||||
testWebDetector.stopPeriodicChecks();
|
||||
});
|
||||
|
||||
tap.test('should detect the platform', async () => {
|
||||
const platform = testWebDetector.platform.detectPlatform();
|
||||
console.log(platform);
|
||||
});
|
||||
|
||||
console.log('hi');
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/webdetector',
|
||||
version: '2.0.0',
|
||||
version: '2.0.2',
|
||||
description: 'detect different environments within the browser'
|
||||
}
|
||||
|
11
ts/index.ts
11
ts/index.ts
@ -53,10 +53,17 @@ export class WebDetector {
|
||||
return reachesInternet;
|
||||
}
|
||||
|
||||
async startPeriodicChecks() {
|
||||
while (true) {
|
||||
private periodicChecksRunning = false;
|
||||
|
||||
public async startPeriodicChecks() {
|
||||
this.periodicChecksRunning = true;
|
||||
while (this.periodicChecksRunning) {
|
||||
await this.isOnline();
|
||||
await plugins.smartdelay.delayFor(3000);
|
||||
}
|
||||
}
|
||||
|
||||
public async stopPeriodicChecks() {
|
||||
this.periodicChecksRunning = false;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ export type TWebPlatform = 'android' | 'ios' | 'windows' | 'mac' | 'linux' | 'un
|
||||
|
||||
export class Platform {
|
||||
public detectPlatform(): TWebPlatform {
|
||||
const userAgent = navigator?.userAgent?.toLowerCase();
|
||||
const userAgent = globalThis?.navigator?.userAgent?.toLowerCase();
|
||||
|
||||
if (!userAgent) {
|
||||
return 'unknown';
|
||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user