another attempt to implement on /offline
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good Details

2022.01
Willem Dantuma 2020-07-22 18:49:15 +02:00
parent 10bdd27608
commit e525227865
1 changed files with 19 additions and 12 deletions

View File

@ -46,7 +46,24 @@ export class AppComponent implements OnInit, OnDestroy {
private meta: Meta,
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());
}
}
@ -103,17 +120,7 @@ export class AppComponent implements OnInit, OnDestroy {
if (x === 27) {
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() {
// Subscription clean-up