react-native-simple-openvpn not connecting.
aum1618 opened this issue · 4 comments
Bug description:
When I try to connect my react native app to the vpn server I get this error: TypeError: Cannot read property 'connect' of null
. The vpn is active on aws cloud service.
Expected behavior:
The app is very basic. I did not add anything to it yet first I wanted to check if the vpn was working or not.I added this code to my app,tsx:
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React, {useEffect} from 'react';
import {
Button,
Platform,
SafeAreaView,
StatusBar,
Text,
useColorScheme,
} from 'react-native';
import RNSimpleOpenvpn, {
addVpnStateListener,
removeVpnStateListener,
} from 'react-native-simple-openvpn';
import {Colors} from 'react-native/Libraries/NewAppScreen';
const isIPhone = Platform.OS === 'ios';
function App(): JSX.Element {
useEffect(() => {
let isMounted = true;
async function observeVpn() {
if (isIPhone) {
await RNSimpleOpenvpn.observeState();
}
addVpnStateListener(e => {
// Handle VPN state changes
console.log(e);
});
}
if (isMounted) {
observeVpn();
}
return () => {
isMounted = false;
async function cleanup() {
if (isIPhone) {
await RNSimpleOpenvpn.stopObserveState();
}
removeVpnStateListener();
}
cleanup();
};
}, []);
async function startOvpn() {
try {
await RNSimpleOpenvpn.connect({
remoteAddress: '16.16.67.136 943',
ovpnFileName: 'client',
assetsPath: 'ovpn/',
providerBundleIdentifier: 'com.example.RNSimpleOvpnTest.NEOpenVPN',
localizedDescription: 'RNSimpleOvpn',
username: '<username>',
password: '<password>',
});
} catch (error) {
console.log(error);
}
}
async function stopOvpn() {
try {
await RNSimpleOpenvpn.disconnect();
} catch (error) {
console.log(error);
}
}
const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
return (
<SafeAreaView style={backgroundStyle}>
<StatusBar
barStyle={isDarkMode ? 'light-content' : 'dark-content'}
backgroundColor={backgroundStyle.backgroundColor}
/>
<Text>Hello</Text>
<Button onPress={startOvpn} title="Start Vpn" />
<Button onPress={stopOvpn} title="Stop Vpn" />
</SafeAreaView>
);
}
export default App;
am I using it wrong? please help!!
Environment:
- platform: windows
- "react-native: "0.71.11",
- "react-native-simple-openvpn": "^2.1.0"
Please upload a screenshot of the error
For me on notification it says 'No process running.', what should i do?
[9:59:29 AM] {"level":"LEVEL_START","message":"VPN_GENERATE_CONFIG","state":1}
[9:59:29 AM] {"level":"LEVEL_NOTCONNECTED","message":"NOPROCESS","state":0}
For me on notification it says 'No process running.', what should i do?
[9:59:29 AM] {"level":"LEVEL_START","message":"VPN_GENERATE_CONFIG","state":1} [9:59:29 AM] {"level":"LEVEL_NOTCONNECTED","message":"NOPROCESS","state":0}
Same error, did you fix it?
I had the same error and after investigating native logs in LogCat I found that the original error was OpenVPNThread Got java.lang.NullPointerException: Attempt to invoke virtual method 'void java.lang.Process.destroy()' on a null object reference I/VpnState: NOPROCESS No process running. LEVEL_NOTCONNECTED
I added android:extractNativeLibs="true"
to <application>
like this
<application ... android:extractNativeLibs="true">
in android/app/src/main/AndroidManifest.xml
and it worked! The error has gone