diff --git a/projects/common/src/fm/components/app/app.component.ts b/projects/common/src/fm/components/app/app.component.ts index 6ac90e7..3aae906 100644 --- a/projects/common/src/fm/components/app/app.component.ts +++ b/projects/common/src/fm/components/app/app.component.ts @@ -46,7 +46,24 @@ export class AppComponent implements OnInit, OnDestroy { private meta: Meta, private store: Store, 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