diff --git a/test/test.both.ts b/test/test.both.ts index d3fda03..dd458c5 100644 --- a/test/test.both.ts +++ b/test/test.both.ts @@ -19,6 +19,7 @@ tap.test('should be online', async () => { testWebDetector.onlineObservable.subscribe((state) => { console.log(state); }); + testWebDetector.stopPeriodicChecks(); }); tap.test('should detect the platform', async () => { diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index db3a2ba..263a041 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@pushrocks/webdetector', - version: '2.0.1', + version: '2.0.2', description: 'detect different environments within the browser' } diff --git a/ts/index.ts b/ts/index.ts index ae79dda..fa055b0 100644 --- a/ts/index.ts +++ b/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; + } }