another attempt to implement on /offline
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
parent
10bdd27608
commit
e525227865
@ -47,6 +47,23 @@ export class AppComponent implements OnInit, OnDestroy {
|
|||||||
private store: Store<appReducers.State>,
|
private store: Store<appReducers.State>,
|
||||||
private eventService: EventService,
|
private eventService: EventService,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
var connection = navigator['connection'] || navigator['mozConnection'] || navigator['webkitConnection'];
|
||||||
|
if(connection) {
|
||||||
|
this.setOnOffline(connection);
|
||||||
|
connection.addEventListener('change', () => {
|
||||||
|
this.setOnOffline(connection);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setOnOffline(connection:any) {
|
||||||
|
console.debug(connection);
|
||||||
|
if(connection.downlink == 0) {
|
||||||
|
this.store.dispatch(new commonActions.Offline());
|
||||||
|
} else {
|
||||||
|
this.store.dispatch(new commonActions.Online());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -105,16 +122,6 @@ export class AppComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('window:online', ['$event'])
|
|
||||||
onOnline(event: Event) {
|
|
||||||
this.store.dispatch(new commonActions.Online());
|
|
||||||
}
|
|
||||||
|
|
||||||
@HostListener('window:offline', ['$event'])
|
|
||||||
onOffline(event: Event) {
|
|
||||||
this.store.dispatch(new commonActions.Offline());
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
// Subscription clean-up
|
// Subscription clean-up
|
||||||
if(this.routerSub$) this.routerSub$.unsubscribe();
|
if(this.routerSub$) this.routerSub$.unsubscribe();
|
||||||
|
Loading…
Reference in New Issue
Block a user