Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor() {
super();
this.online = true;
NativeNetInfo.getConnectionInfo().then(connectionState => {
this.online = hasOnlineConnectionState(connectionState);
});
NativeNetInfo.addEventListener('connectionChange', (connectionState)=>{
var isNowOnline = hasOnlineConnectionState(connectionState);
// React Native counts the switch from Wi-Fi to Cellular
// as a state change. Return if current and previous states
// are both online/offline
if (this.online === isNowOnline) return;
this.online = isNowOnline;
if (this.online){
this.emit("online");
} else {
this.emit("offline");
}
});
}
constructor() {
super();
this.online = true;
NativeNetInfo.getConnectionInfo().then(connectionState => {
this.online = hasOnlineConnectionState(connectionState);
});
NativeNetInfo.addEventListener('connectionChange', (connectionState)=>{
var isNowOnline = hasOnlineConnectionState(connectionState);
// React Native counts the switch from Wi-Fi to Cellular
// as a state change. Return if current and previous states
// are both online/offline
if (this.online === isNowOnline) return;
this.online = isNowOnline;
if (this.online){
this.emit("online");
} else {
this.emit("offline");
}
componentDidMount() {
const { dispatch } = this.props;
handleInitialNotification(dispatch);
this.netInfoDisconnectCallback = NetInfo.addEventListener(this.handleConnectivityChange);
AppState.addEventListener('change', this.handleAppStateChange);
AppState.addEventListener('memoryWarning', this.handleMemoryWarning);
SafeArea.getSafeAreaInsetsForRootView().then(params =>
dispatch(initSafeAreaInsets(params.safeAreaInsets)),
);
// $FlowFixMe: libdef wrongly says callback's parameter is optional
Orientation.addOrientationListener(this.handleOrientationChange);
this.notificationListener.start();
}
ssid = await NetworkInfo.getSSID();
} catch (e) {
bugsnag.notify(e);
} finally {
// Even if we don't get the SSID, we still want to show that a wifi
// network is connected.
setSsid(ssid);
}
};
// When the modal opens, start announcing this device as available for sync
api.syncJoin(deviceName);
// Subscribe to peer updates
subscriptions.push(api.addPeerListener(setServerPeers));
// Subscribe to NetInfo to know when the user connects/disconnects to wifi
subscriptions.push({
remove: NetInfo.addEventListener(handleConnectionChange)
});
// Keep the screen awake whilst on this screen
KeepAwake.activate();
return () => {
// When the modal closes, stop announcing for sync
api.syncLeave();
// Unsubscribe all listeners
subscriptions.forEach(s => s.remove());
// Turn off keep screen awake
KeepAwake.deactivate();
};
}, []);
async componentDidMount() {
const { pingInterval } = this.props;
const handler = this.getConnectionChangeHandler();
NetInfo.isConnected.addEventListener('connectionChange', handler);
// On Android the listener does not fire on startup
if (Platform.OS === 'android') {
const netConnected = await NetInfo.isConnected.fetch();
handler(netConnected);
}
if (pingInterval > 0) {
connectivityInterval.setup(this.intervalHandler, pingInterval);
}
}
componentWillMount() {
if (this.props.checkNetwork) {
NetInfo.isConnected.addEventListener('connectionChange', this._handleConnectivityChange);
// componentWillUnmount unsets this._handleConnectivityChange in case the component unmounts before this fetch resolves
NetInfo.isConnected.fetch().done(this._handleConnectivityChange);
}
this._processSource(this.props.source, true);
}
async componentDidMount() {
const state = await NetInfo.fetch()
let newState = {}
newState.connectedToWifi = state.type === 'wifi' && state.isConnected
let host = await AsyncStorage.getItem('@ipFinder.host')
// Check if we have host or that current is still available and if we are connected to wifi
// other check for host
if ((!host || !(await this.isHost(host))) && newState.connectedToWifi) {
host = null
SplashScreen.hide()
if (await deviceInfo.isEmulator()) {
// If we are a emulator then check the host ip
if (await this.isHost('10.0.2.2:5000')) {
return eventChannel((emit) => {
return NetInfo.addEventListener((state) => emit(state))
})
}
componentDidMount() {
this._eventCounter = 0;
NetInfo.getConnectionInfo()
.then(connectionInfo => this.setState({ connectionInfo }))
.catch(console.warn);
this._ensureIsConnectionExpensiveIsUpToDate();
this._subscription = NetInfo.addEventListener(
'connectionChange',
this._handleConnectionChange
) as unknown as Subscription;
this._isConnectedSubscription = NetInfo.isConnected.addEventListener(
'connectionChange',
this._handleIsConnectedChange
) as unknown as Subscription;
}
export default function init(store: Store) {
BackHandler.addEventListener("hardwareBackPress", () => {
const { nav }: { nav: NavigationState } = store.getState();
const { index } = nav;
if (index > 1) {
store.dispatch(StackActions.pop({}));
return true;
}
return false;
});
NetInfo.fetch().then(state => {
store.dispatch(NetworkActions.update(state));
});
NetInfo.addEventListener(state => {
if (typeof state === "object") {
store.dispatch(NetworkActions.update(state));
}
});
common(store);
}