Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-native-simple-openvpn not connecting. #51

Open
aum1618 opened this issue Jun 16, 2023 · 2 comments
Open

react-native-simple-openvpn not connecting. #51

aum1618 opened this issue Jun 16, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@aum1618
Copy link

aum1618 commented Jun 16, 2023

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"
@aum1618 aum1618 added the bug Something isn't working label Jun 16, 2023
@ccnnde
Copy link
Owner

ccnnde commented Jun 19, 2023

Please upload a screenshot of the error

@amma-dev
Copy link

amma-dev commented Nov 8, 2023

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants