account for LAN failure

This commit is contained in:
Matt Hill
2021-07-12 12:09:00 -06:00
committed by Aiden McClelland
parent e0478ba46c
commit 7a144b4d25
2 changed files with 18 additions and 10 deletions

View File

@@ -127,21 +127,25 @@ export class AppComponent {
let link: string let link: string
switch (connectionFailure) { switch (connectionFailure) {
case ConnectionFailure.Network: case ConnectionFailure.Network:
message = 'Your phone or computer has no network connection.' message = 'Phone or computer has no network connection.'
break break
case ConnectionFailure.Diagnosing: case ConnectionFailure.Diagnosing:
message = new IonicSafeString('Running network diagnostics <ion-spinner name="dots"></ion-spinner>') message = new IonicSafeString('Running network diagnostics <ion-spinner name="dots"></ion-spinner>')
break break
case ConnectionFailure.Embassy: case ConnectionFailure.Embassy:
message = 'Your Embassy appears to be offline.' message = 'Embassy appears to be offline.'
link = 'https://docs.start9.com/support/FAQ/setup-faq.html#embassy-offline' link = 'https://docs.start9.com/support/FAQ/setup-faq.html#embassy-offline'
break break
case ConnectionFailure.Tor: case ConnectionFailure.Tor:
message = 'Your phone or computer is currently unable to connect over Tor.' message = 'Browser unable to connect over Tor.'
link = 'https://docs.start9.com/support/FAQ/setup-faq.html#tor-failure' link = 'https://docs.start9.com/support/FAQ/setup-faq.html#tor-failure'
break break
case ConnectionFailure.Internet: case ConnectionFailure.Internet:
message = 'Your phone or computer is unable to connect to the Internet.' message = 'Phone or computer has no Internet.'
break
case ConnectionFailure.Lan:
message = 'Embassy not found on Local Area Network.'
link = 'https://docs.start9.com/support/FAQ/setup-faq.html#lan-failure'
break break
} }
await this.presentToastOffline(message, link) await this.presentToastOffline(message, link)

View File

@@ -3,6 +3,7 @@ import { BehaviorSubject, combineLatest, fromEvent, merge, Subscription } from '
import { ConnectionStatus, PatchDbModel } from './patch-db/patch-db.service' import { ConnectionStatus, PatchDbModel } from './patch-db/patch-db.service'
import { HttpService, Method } from './http.service' import { HttpService, Method } from './http.service'
import { distinctUntilChanged } from 'rxjs/operators' import { distinctUntilChanged } from 'rxjs/operators'
import { ConfigService } from './config.service'
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@@ -14,6 +15,7 @@ export class ConnectionService {
constructor ( constructor (
private readonly httpService: HttpService, private readonly httpService: HttpService,
private readonly configService: ConfigService,
private readonly patch: PatchDbModel, private readonly patch: PatchDbModel,
) { } ) { }
@@ -30,26 +32,27 @@ export class ConnectionService {
combineLatest([this.networkState$.pipe(distinctUntilChanged()), this.patch.watchConnection$().pipe(distinctUntilChanged())]) combineLatest([this.networkState$.pipe(distinctUntilChanged()), this.patch.watchConnection$().pipe(distinctUntilChanged())])
.subscribe(async ([network, connectionStatus]) => { .subscribe(async ([network, connectionStatus]) => {
console.log('CONNECTION STATUS', connectionStatus)
const addrs = this.patch.data['server-info']?.['connection-addresses'] const addrs = this.patch.data['server-info']?.['connection-addresses']
if (connectionStatus !== ConnectionStatus.Disconnected) { if (connectionStatus !== ConnectionStatus.Disconnected) {
this.connectionFailure$.next(ConnectionFailure.None) this.connectionFailure$.next(ConnectionFailure.None)
} else if (!network) { } else if (!network) {
this.connectionFailure$.next(ConnectionFailure.Network) this.connectionFailure$.next(ConnectionFailure.Network)
} else { } else if (!this.configService.isTor()) {
console.log('diagnosing') this.connectionFailure$.next(ConnectionFailure.Lan)
} {
// diagnosing
this.connectionFailure$.next(ConnectionFailure.Diagnosing) this.connectionFailure$.next(ConnectionFailure.Diagnosing)
const torSuccess = await this.testAddrs(addrs?.tor || []) const torSuccess = await this.testAddrs(addrs?.tor || [])
if (torSuccess) { if (torSuccess) {
console.log('TOR SUCCESS, EMBASSY IS PROBLEM') // TOR SUCCESS, EMBASSY IS PROBLEM
this.connectionFailure$.next(ConnectionFailure.Embassy) this.connectionFailure$.next(ConnectionFailure.Embassy)
} else { } else {
const clearnetSuccess = await this.testAddrs(addrs?.clearnet || []) const clearnetSuccess = await this.testAddrs(addrs?.clearnet || [])
if (clearnetSuccess) { if (clearnetSuccess) {
console.log('CLEARNET SUCCESS, TOR IS PROBLEM') // CLEARNET SUCCESS, TOR IS PROBLEM
this.connectionFailure$.next(ConnectionFailure.Tor) this.connectionFailure$.next(ConnectionFailure.Tor)
} else { } else {
console.log('INTERNET IS PROBLEM') // INTERNET IS PROBLEM
this.connectionFailure$.next(ConnectionFailure.Internet) this.connectionFailure$.next(ConnectionFailure.Internet)
} }
} }
@@ -89,5 +92,6 @@ export enum ConnectionFailure {
Network = 'network', Network = 'network',
Embassy = 'embassy', Embassy = 'embassy',
Tor = 'tor', Tor = 'tor',
Lan = 'lan',
Internet = 'internet', Internet = 'internet',
} }