Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
26 lines (21 sloc) 873 Bytes
import { NetworkStatus, NetworkStatusChangeCallback } from "./NetworkStatus";
declare var document: any;
/**
* Cordova networks status implementation based on: cordova-plugin-network-information
* See: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-network-information
*/
export class CordovaNetworkStatus implements NetworkStatus {
public onStatusChangeListener(callback: NetworkStatusChangeCallback): void {
if (document) {
document.addEventListener("online", () => callback.onStatusChange({online: true}), false);
document.addEventListener("offline", () => callback.onStatusChange({online: false}), false);
}
}
public isOffline(): Promise<boolean> {
return new Promise((resolve) => {
document.addEventListener("deviceready", () => {
resolve(!window.navigator.onLine);
}, false);
});
}
}
You can’t perform that action at this time.