better network monitoring

This commit is contained in:
Matt Hill
2021-07-01 16:18:49 -06:00
committed by Aiden McClelland
parent 80db9b71b9
commit d8ef531721
14 changed files with 295 additions and 244 deletions

View File

@@ -12,7 +12,7 @@ import { LoadingOptions } from '@ionic/core'
import { PatchDbModel } from './models/patch-db/patch-db-model'
import { HttpService } from './services/http.service'
import { ServerStatus } from './models/patch-db/data-model'
import { ConnectionService } from './services/connection.service'
import { ConnectionFailure, ConnectionService } from './services/connection.service'
@Component({
selector: 'app-root',
@@ -83,6 +83,7 @@ export class AppComponent {
this.http.authReqEnabled = true
this.showMenu = true
this.patch.start()
this.connectionService.start()
// watch network
this.watchConnection(auth)
// watch router to highlight selected menu item
@@ -95,6 +96,7 @@ export class AppComponent {
} else if (auth === AuthState.UNVERIFIED) {
this.http.authReqEnabled = false
this.showMenu = false
this.connectionService.stop()
this.patch.stop()
this.storage.clear()
this.router.navigate(['/login'], { replaceUrl: true })
@@ -107,13 +109,13 @@ export class AppComponent {
}
private watchConnection (auth: AuthState): void {
this.connectionService.monitor$()
this.connectionService.watch$()
.pipe(
distinctUntilChanged(),
takeWhile(() => auth === AuthState.VERIFIED),
)
.subscribe(internet => {
if (!internet) {
.subscribe(connectionFailure => {
if (connectionFailure !== ConnectionFailure.None) {
this.presentToastOffline()
} else {
if (this.offlineToast) {
@@ -121,7 +123,6 @@ export class AppComponent {
this.offlineToast = undefined
}
}
console.log('INTERNET CONNECTION', internet)
})
}