Skip to content

Commit

Permalink
fix(pubsub): Add distinct RN Reachibility implementation (aws-amplify…
Browse files Browse the repository at this point in the history
…#10175)

* fix(pubsub): Add distinct RN Reachibility implementation

* fix(PubSub): Fix monitor tests
  • Loading branch information
stocaaro authored Aug 9, 2022
1 parent 88f118e commit 5f427f3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/pubsub/src/utils/ConnectionStateMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import { Reachability } from '@aws-amplify/core';
import Observable, { ZenObservable } from 'zen-observable-ts';
import { ConnectionState } from '../index';
import { ReachabilityMonitor } from './ReachabilityMonitor';

// Internal types for tracking different connection states
type LinkedConnectionState = 'connected' | 'disconnected';
Expand Down Expand Up @@ -85,13 +86,13 @@ export class ConnectionStateMonitor {
private enableNetworkMonitoring() {
// Maintain the network state based on the reachability monitor
if (this._networkMonitoringSubscription === undefined) {
this._networkMonitoringSubscription = new Reachability()
.networkMonitor()
.subscribe(({ online }) => {
this._networkMonitoringSubscription = ReachabilityMonitor().subscribe(
({ online }) => {
this.record(
online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE
);
});
}
);
}
}

Expand Down
5 changes: 5 additions & 0 deletions packages/pubsub/src/utils/ReachabilityMonitor/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Reachability } from '@aws-amplify/core';
import { default as NetInfo } from '@react-native-community/netinfo';

export const ReachabilityMonitor = () =>
new Reachability().networkMonitor(NetInfo);
3 changes: 3 additions & 0 deletions packages/pubsub/src/utils/ReachabilityMonitor/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Reachability } from '@aws-amplify/core';

export const ReachabilityMonitor = () => new Reachability().networkMonitor();

0 comments on commit 5f427f3

Please sign in to comment.