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

@ -46,7 +46,24 @@ export class AppComponent implements OnInit, OnDestroy {
private meta: Meta, private meta: Meta,
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());
}
} }
@ -103,17 +120,7 @@ export class AppComponent implements OnInit, OnDestroy {
if (x === 27) { if (x === 27) {
this.store.dispatch(new commonActions.Escape(true,false)); this.store.dispatch(new commonActions.Escape(true,false));
} }
} }
@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