initial
This commit is contained in:
24
ts/index.ts
Normal file
24
ts/index.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import * as plugins from './webdetector.plugins';
|
||||
|
||||
export class WebDetector {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async isOnline() {
|
||||
const navigatorOnline = window.navigator.onLine
|
||||
let reachesGoogle: boolean = false;
|
||||
if (navigatorOnline) {
|
||||
const controller = new AbortController();
|
||||
const fetchPromise = fetch('https://google.com', { signal: controller.signal });
|
||||
const timeout = setTimeout(() => {
|
||||
controller.abort();
|
||||
}, 5000);
|
||||
|
||||
await fetchPromise.then(async response => {
|
||||
reachesGoogle = true
|
||||
});
|
||||
}
|
||||
return reachesGoogle;
|
||||
}
|
||||
}
|
4
ts/webdetector.plugins.ts
Normal file
4
ts/webdetector.plugins.ts
Normal file
@ -0,0 +1,4 @@
|
||||
const removeme = {};
|
||||
export {
|
||||
removeme
|
||||
}
|
Reference in New Issue
Block a user