npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rn-openvpn

v1.0.3

Published

React Native Open VPN Module

Downloads

7

Readme

react-native-simple-openvpn

npm version platforms GNU General Public License

English | 简体中文

A simple react native module to interact with OpenVPN

Versions

| RNSimpleOpenvpn | React Native | | ------------------------------------------------------------------- | ------------ | | npm version | 0.56 ~ 0.65 |

Preview

Installation

Adding dependencies

# npm
npm install --save rn-openvpn

# or use yarn
yarn add rn-openvpn

Link

From react-native 0.60 autolinking will take care of the link step

react-native link rn-openvpn

iOS

If using CocoaPods, run it in the ios/ directory

pod install

See iOS Guide for iOS side Network Extension configuration and OpenVPN integration

Usage

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

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

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

            addVpnStateListener((e) => {
                // ...
            });
        }

        observeVpn();

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

            removeVpnStateListener();
        };
    });

    async function startOvpn() {
        try {
            await RNSimpleOpenvpn.connect({
                remoteAddress: '192.168.1.1 3000',
                config: 'XXXX',
                username: '',
                password: '',
                providerBundleIdentifier: 'com.example.RNSimpleOvpnTest.NEOpenVPN',
                localizedDescription: 'RNSimpleOvpn',
            });
        } catch (error) {
            // ...
        }
    }

    async function stopOvpn() {
        try {
            await RNSimpleOpenvpn.disconnect();
        } catch (error) {
            // ...
        }
    }

    function printVpnState() {
        console.log(JSON.stringify(RNSimpleOpenvpn.VpnState, undefined, 2));
    }

    // ...
};

export default App;

Methods

| Name | iOS | Android | Parameters | Return | Description | | ---------------------- | --- | ------- | -------------------------------------------------------- | ------- | ------------------------------------------- | | connect | ✅ | ✅ | options: VpnOptions | promise | Connecting to OpenVPN | | disconnect | ✅ | ✅ | none | promise | Close the OpenVPN connection | | observeState | ✅ | ❌ | none | promise | Listening for VPN status | | stopObserveState | ✅ | ❌ | none | promise | Stop listening to VPN status | | addVpnStateListener | ✅ | ✅ | callback: (e: VpnEventParams) => void | void | Add VPN status change event listener | | removeVpnStateListener | ✅ | ✅ | none | void | Remove the VPN status change event listener |

Properties

| Name | Value | Description | | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | | VpnState | VPN_STATE_DISCONNECTED = 0 VPN_STATE_CONNECTING = 1 VPN_STATE_CONNECTED = 2 VPN_STATE_DISCONNECTING = 3 VPN_OTHER_STATE = 4 | VPN Current Status |

Types

VpnOptions

interface VpnOptions {
    remoteAddress?: string,
    config?: string,
    username?: string,
    password?: string,
    providerBundleIdentifier: string,
    localizedDescription?: string,
}

remoteAddress

VPN server address, the format is <ip> <port>, use the address in the configuration file of xxx.ovpn when it is not passed in

ovpnFileName

The name of the OpenVPN configuration file, without extensions, using the default name client if not passed in

assetsPath

Android only,the path to the OpenVPN configuration file under android/app/src/main/assets/

  • assetsPath is '' when not passed in, the file path is assets/xxx.ovpn
  • When passing in a path, such as 'ovpn/', the file path is assets/ovpn/xxx.ovpn

providerBundleIdentifier

iOS only,the bundle identifier of the Network Extension target

localizedDescription

iOS only,the localized description name of the app in Settings -> VPN. If it is not passed in, the default name RNSimpleOpenvpn will be used

VpnEventParams

interface VpnEventParams {
    state: RNSimpleOpenvpn.VpnState; // VPN Status
    message: string; // VPN Status Related Messages
    level?: string; // Description of the connection status provided by the Android OpenVPN library
}

Attention

xxx.ovpn configuration file

Don't forget to add the configuration file to your project

  • The Android path is android/app/src/main/assets/,create a new assets folder if you don't have one

  • The iOS path is the main bundle, just drag and drop the file into the project

    ios-ovpn-file

The format of the line where remote is located in the file must be of the following form

...
remote <IP address> <port>
...

If you don't need to dynamically modify the remote address in the configuration file, the same configuration file is used for Android and iOS, and the remoteAddress of options can be left out

However, if you need to dynamically change the remote address in the configuration file, the iOS configuration file needs to comment out the line where remote is located (below) and always pass remoteAddress for options

...
;remote <IP address> <port>>
...

OpenVPN library

The following items were used in this project

  • Android - ics-openvpn, for personal project reasons, the Android side is currently using an older version of its core library
  • iOS - OpenVPNAdapter v0.8.0

Todo

  • [ ] Resolve RN 0.65 warning
  • [ ] Upgrade to the latest Android OpenVPN library

License

react-native-simple-openvpn is available under the GPLv2 license. See the LICENSE file for more information