Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
23 lines (19 sloc) 740 Bytes
import { NetworkStatus, NetworkStatusChangeCallback } from "./NetworkStatus";
declare var window: any;
/**
* Web networks status implementation based on: Mozilla
* See: https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine
*/
export class WebNetworkStatus implements NetworkStatus {
public onStatusChangeListener(callback: NetworkStatusChangeCallback): void {
if (window) {
window.addEventListener("online", () => callback.onStatusChange({online: true}), false);
window.addEventListener("offline", () => callback.onStatusChange({online: false}), false);
}
}
public isOffline(): Promise<boolean> {
return new Promise((resolve) => {
resolve(!window.navigator.onLine);
});
}
}
You can’t perform that action at this time.