1 |
|
2 |
|
3 | import Observable from 'zen-observable-ts';
|
4 | import { ConsoleLogger as Logger } from '../Logger';
|
5 | var logger = new Logger('Reachability', 'DEBUG');
|
6 | var ReachabilityNavigator = (function () {
|
7 | function ReachabilityNavigator() {
|
8 | }
|
9 | ReachabilityNavigator.prototype.networkMonitor = function (netInfo) {
|
10 | |
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | if (!(netInfo && netInfo.addEventListener)) {
|
18 | throw new Error('NetInfo must be passed to networkMonitor to enable reachability in React Native');
|
19 | }
|
20 | return new Observable(function (observer) {
|
21 | logger.log('subscribing to reachability in React Native');
|
22 | var unsubscribe = netInfo.addEventListener(function (_a) {
|
23 | var isInternetReachable = _a.isInternetReachable;
|
24 |
|
25 |
|
26 | if (typeof isInternetReachable === 'boolean') {
|
27 | var online = isInternetReachable;
|
28 | logger.log('Notifying reachability change', online);
|
29 | observer.next({ online: online });
|
30 | }
|
31 | });
|
32 | return function () {
|
33 | unsubscribe();
|
34 | };
|
35 | });
|
36 | };
|
37 | return ReachabilityNavigator;
|
38 | }());
|
39 | export default ReachabilityNavigator;
|