add analytics
This commit is contained in:
30
app/src/services/analytics/NetworkDetector.js
Normal file
30
app/src/services/analytics/NetworkDetector.js
Normal file
@@ -0,0 +1,30 @@
|
||||
export class NetworkDetector {
|
||||
constructor() {
|
||||
this.isOnline = navigator.onLine;
|
||||
this.listeners = [];
|
||||
}
|
||||
|
||||
subscribe(listener) {
|
||||
this.listeners.push(listener);
|
||||
|
||||
window.addEventListener('online', () => {
|
||||
this.isOnline = true;
|
||||
this.listeners.forEach(l => l(true));
|
||||
});
|
||||
|
||||
window.addEventListener('offline', () => {
|
||||
this.isOnline = false;
|
||||
this.listeners.forEach(l => l(false));
|
||||
});
|
||||
|
||||
return () => {
|
||||
this.listeners = this.listeners.filter(l => l !== listener);
|
||||
};
|
||||
}
|
||||
|
||||
getStatus() {
|
||||
return this.isOnline;
|
||||
}
|
||||
}
|
||||
|
||||
export const networkDetector = new NetworkDetector();
|
||||
Reference in New Issue
Block a user