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

@cocomine/react-native-simple-openvpn

v2.1.3

Published

React Native Open VPN Module

Downloads

142

Readme

react-native-simple-openvpn github stars

npm latest download month download total PRs welcome all contributors platforms GNU General Public License

简体中文 | English

react-native-simple-openvpn 提供了与 OpenVPN 交互的接口

如果本项目对你有所帮助,请 star 🌟 鼓励,谢谢 🙏

版本

| RNSimpleOpenvpn | React Native | | --------------- | ------------- | | 1.0.0 ~ 1.2.0 | 0.56 ~ 0.66 | | >= 2.0.0 | >= 0.63 |

详细信息请参考更改日志

预览

安装

添加依赖

# npm
npm install --save react-native-simple-openvpn

# or use yarn
yarn add react-native-simple-openvpn

Link

从 react-native 0.60 开始,autolinking 将负责链接的步骤

react-native link react-native-simple-openvpn

Android

在项目的 android/settings.gradle 中添加以下代码:

rootProject.name = 'example'
+ include ':vpnLib'
+ project(':vpnLib').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-simple-openvpn/vpnLib')
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'

导入 jniLibs

由于存在文件大小的限制,jniLibs 无法随模块一起发布到 npm 上。故使用 GitHub Releases 中的 assets 来代替

下载并解压你需要的相应架构的资源,然后将其放入 android/app/src/main/jniLibs 中(如果 jniLibs 文件夹不存在则手动新建一个)

project
├── android
│   ├── app
│   │   └── src
│   │       └── main
│   │           └── jniLibs
│   │               ├── arm64-v8a
│   │               ├── armeabi-v7a
│   │               ├── x86
│   │               └── x86_64
│   └── ...
├── ios
└── ...

iOS

如果使用 CocoaPods, 在 ios/ 目录下运行

pod install

iOS 端 Network Extension 配置以及 OpenVPN 的集成请参阅 iOS 指南

后台退出 App 时关闭 VPN 连接

在项目的 AppDelegate.m 中添加以下代码:

+ #import "RNSimpleOpenvpn.h"

@implementation AppDelegate

// ...

+ - (void)applicationWillTerminate:(UIApplication *)application
+ {
+   [RNSimpleOpenvpn dispose];
+ }

@end

请确保 Build Settings 的 Header Search Paths 包含以下路径:

$(SRCROOT)/../node_modules/react-native-simple-openvpn/ios

或者, 如果你使用 CocoaPods 的话,Header Search Paths 应该会自动包含以下路径:

"${PODS_ROOT}/Headers/Public/react-native-simple-openvpn"

示例

项目示例

用法

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',
        ovpnFileName: 'client',
        assetsPath: 'ovpn/',
        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;

更多内容请查看 API Reference

OpenVPN library

本项目使用到了以下项目

Star History

star history chart

Contributors

感谢以下所有做出贡献的人

contributors list

License

GPLv2 © Nor Cod