add server ping check
This commit is contained in:
parent
f98369436e
commit
22c7dc2c95
@ -11,8 +11,6 @@ import {Database} from './db/Database';
|
|||||||
import {DatabaseColumn} from './db/DatabaseColumn';
|
import {DatabaseColumn} from './db/DatabaseColumn';
|
||||||
import {DatabaseEntry} from './db/DatabaseEntry';
|
import {DatabaseEntry} from './db/DatabaseEntry';
|
||||||
import {FileGroup} from './db/FileGroup';
|
import {FileGroup} from './db/FileGroup';
|
||||||
import {Page} from './db/Page'
|
|
||||||
import {PageNode} from "./db/PageNode";
|
|
||||||
|
|
||||||
export class ResourceNotAvailableOfflineError extends Error {
|
export class ResourceNotAvailableOfflineError extends Error {
|
||||||
constructor(msg = 'This resource is not yet available offline on this device.') {
|
constructor(msg = 'This resource is not yet available offline on this device.') {
|
||||||
@ -43,10 +41,30 @@ export class ApiService {
|
|||||||
if ( !isConnected ) {
|
if ( !isConnected ) {
|
||||||
this.makeOffline();
|
this.makeOffline();
|
||||||
} else {
|
} else {
|
||||||
this.makeOnline(); // TODO add checks for server.
|
this.checkOnline().then(isOnline => {
|
||||||
|
if ( isOnline ) {
|
||||||
|
this.makeOnline();
|
||||||
|
} else {
|
||||||
|
this.makeOffline();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.checkOnline().then(isConnected => {
|
||||||
|
if ( !isConnected ) {
|
||||||
|
this.makeOffline();
|
||||||
|
} else {
|
||||||
|
this.makeOnline();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public checkOnline(): Promise<boolean> {
|
||||||
|
return fetch(this.statUrl).then(resp => {
|
||||||
|
return resp && (resp.ok || resp.type === 'opaque');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public makeOffline() {
|
public makeOffline() {
|
||||||
this.offline = true;
|
this.offline = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user