Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .flowconfig

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ project.xcworkspace
#
node_modules/
npm-debug.log

.idea/
.gradle/
8 changes: 0 additions & 8 deletions .vscode/settings.json

This file was deleted.

4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)
MIT License

Copyright (c) 2019 Dmitri Vasiliev
Copyright (c) 2022 Samet Kızılaslan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
112 changes: 35 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,92 +1,50 @@
# react-native-vpn-detect

A React Native wrapper to determine if the current iOS network connection is on a VPN (NetInfo supplies this for Android).

## Installation

```bash
npm i --save react-native-vpn-detect # npm syntax
yarn add react-native-vpn-detect # yarn syntax
```
then enter the `ios` directory and run `pod install` to link the pod to your React Native project.

## Usage

Import the library along with the NativeEventEmitter exported from React Native:
```
import { ..., NativeEventEmitter } from "react-native";
import RNVPNDetect from "react-native-vpn-detect";
```

## Setup:

in componentDidMount, instantiate a new NativeEventEmitter, passing in RNVPNDetect.

```
const RNVPNDetectEmitter = new NativeEventEmitter(RNVPNDetect);

```

Then, add a listener to the EventEmitter instance, and make sure to store it somewhere globally available on the component (e.g. instance variable) so you can unsubscribe from it later.

The listener should take: ```"RNVPNDetect.vpnStateDidChange"``` as the event name to listen to, and a handler of your choosing as the second argument.

```
RootContainer._iosVpnDetectSubscribe = RNVPNDetectEmitter.addListener(
"RNVPNDetect.vpnStateDidChange",
this._handleVpnStateChanged
);
# react-native-vpn-detect
<a href="https://www.buymeacoffee.com/kzlsn" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>

```
## Getting started

RNVPNDetect can be used in two ways:
- Using a timer, which will check for a change in the VPN state at the provided interval, and send an event IF the state has changed
- Manually asking for the current vpn state
`$ npm install react-native-vpn-detect --save`

## Use Timer
### Mostly automatic installation

After following the setup steps above:
`$ react-native link react-native-vpn-detect`

You can then initialize the timer with an interval of your choosing. It defaults to 3s (3000ms) if nothing is passed in.
### Manual installation

```
RNVPNDetect.startTimer(5000)
```

Make sure to unsubscribe from the listener when your component unmounts.
#### iOS

```
componentDidUnmount {
...
if (RootContainer._iosVpnDetectSubscribe) {
RootContainer._iosVpnDetectSubscribe.remove();
RootContainer._iosVpnDetectSubscribe = null;
RNVPNDetect.stopTimer();
}
}
1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
2. Go to `node_modules` ➜ `react-native-vpn-detect` and add `RNNativeVpnDetect.xcodeproj`
3. In XCode, in the project navigator, select your project. Add `libRNNativeVpnDetect.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
4. Run your project (`Cmd+R`)<

```
#### Android

## Manual
1. Open up `android/app/src/main/java/[...]/MainActivity.java`
- Add `import com.reactlibrary.RNNativeVpnDetectPackage;` to the imports at the top of the file
- Add `new RNNativeVpnDetectPackage()` to the list returned by the `getPackages()` method
2. Append the following lines to `android/settings.gradle`:
```
include ':react-native-vpn-detect'
project(':react-native-vpn-detect').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vpn-detect/android')
```
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
```
compile project(':react-native-vpn-detect')
```

After following the steps above, you can manually query the current vpn state by calling:

```
RNVPNDetect.checkIsVpnConnected()
```

This will check the current vpn state and trigger the listener you set up in ```componentDidMount```.

You should still unsubscribe from the listener on unmount, but you can skip the ```stopTimer``` call if you never started one ;)

```
componentDidUnmount {
...
if (RootContainer._iosVpnDetectSubscribe) {
RootContainer._iosVpnDetectSubscribe.remove();
RootContainer._iosVpnDetectSubscribe = null;
}
## Usage
```javascript
* Import Library
import Security from "react-native-vpn-detect";

* Example Usage
async function checkSecurity() {
let detectVPN = await Security.detectVPN().then(response => { return response });
let detectProxy = await Security.detectProxy().then(response => { return response });
}

checkSecurity();
```

22 changes: 22 additions & 0 deletions RNNativeVpnDetect.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
s.name = "RNNativeVpnDetect"
s.version = package['version']
s.summary = package['description']
s.description = package['description']
s.license = package['license']
s.author = package['author']
s.homepage = package['homepage']

s.platforms = { :ios => "9.0", :tvos => "11.0" }
s.ios.deployment_target = '9.0'

s.preserve_paths = 'README.md', 'package.json', 'index.js'
s.source_files = 'iOS/*.{h,m}'
s.source = { :git => 'https://github.com/kzlsnn/react-native-vpn-detect.git' }

s.dependency 'React'
end
Loading