another attempt to implement on /offline
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good

This commit is contained in:
Willem Dantuma 2020-07-22 18:49:15 +02:00
parent 10bdd27608
commit e525227865

View File

@ -47,6 +47,23 @@ export class AppComponent implements OnInit, OnDestroy {
private store: Store<appReducers.State>,
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() {
// Subscription clean-up
if(this.routerSub$) this.routerSub$.unsubscribe();