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

Prepare VPN failed #62

Open
omarsaade opened this issue Apr 18, 2024 · 1 comment
Open

Prepare VPN failed #62

omarsaade opened this issue Apr 18, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@omarsaade
Copy link

omarsaade commented Apr 18, 2024

This is my code :


import React, {useEffect, useState} from 'react';
import {Platform, View, Text, Button} from 'react-native';
import RNSimpleOpenvpn, {
  addVpnStateListener,
  removeVpnStateListener,
} from 'react-native-simple-openvpn';

const isIPhone = Platform.OS === 'ios';

const App = () => {
  const [vpnStatus, setVpnStatus] = useState('Disconnected');

  useEffect(() => {
    async function observeVpn() {
      if (isIPhone) {
        await RNSimpleOpenvpn.observeState();
      }

      addVpnStateListener(e => {
        // Update VPN status
        setVpnStatus(e.state);
      });
    }

    observeVpn();

    return async () => {
      if (isIPhone) {
        await RNSimpleOpenvpn.stopObserveState();
      }

      removeVpnStateListener();
    };
  }, []);

  async function startOvpn() {
    try {
      await RNSimpleOpenvpn.connect({
        remoteAddress: '192.168.1.1 3000',
        ovpnFileName: 'client',
        assetsPath: 'ovpn/',
        providerBundleIdentifier: 'com.example.RNSimpleOvpnTest.NEOpenVPN',
        localizedDescription: 'RNSimpleOvpn',
      });
    } catch (error) {
      console.error('Error connecting to VPN:', error);
    }
  }

  async function stopOvpn() {
    try {
      await RNSimpleOpenvpn.disconnect();
    } catch (error) {
      console.error('Error disconnecting from VPN:', error);
    }
  }

  return (
    <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
      <Text>VPN Status: {vpnStatus}</Text>
      <Button title="Connect" onPress={startOvpn} />
      <Button title="Disconnect" onPress={stopOvpn} />
    </View>
  );
};
export default App;

And this is the error it returns. Note that I'm not an expert in VPN or these services.
Can someone help me understand how to continue and how to solve this error
"Error connecting to VPN: [Error: Prepare VPN failed]"? What am I missing?

Environment:

  • OS:
  • OS version:
  • react-native version:
  • react-native-simple-openvpn version:
@omarsaade omarsaade added the bug Something isn't working label Apr 18, 2024
@ccnnde
Copy link
Owner

ccnnde commented Apr 20, 2024

Please fill in the Environment information and upload the screenshot of the error.

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

2 participants