# react-native-vpn-proxy-detect

A React Native library for detecting VPN and Proxy connections on iOS and Android devices.

## Features

- ✅ Detect VPN connections
- ✅ Detect Proxy connections  
- ✅ iOS and Android support
- ✅ TypeScript support
- ✅ Turbo Module architecture
- ✅ Promise-based API

## Installation

```sh
npm install react-native-vpn-proxy-detect
```

### iOS

Run `cd ios && pod install` to install the iOS dependencies.

### Android

No additional setup required for Android.

## Usage

### Import Methods

```js
// Named imports (recommended)
import { detectVPN, detectProxy } from 'react-native-vpn-proxy-detect';

// Default import (for backward compatibility)
import VpnProxyDetect from 'react-native-vpn-proxy-detect';
```

### Detect VPN Connection

```js
import { detectVPN } from 'react-native-vpn-proxy-detect';

async function checkVPN() {
  try {
    const isVPNActive = await detectVPN();
    console.log('VPN is active:', isVPNActive);
  } catch (error) {
    console.error('Failed to detect VPN:', error);
  }
}
```

### Detect Proxy Connection

```js
import { detectProxy } from 'react-native-vpn-proxy-detect';

async function checkProxy() {
  try {
    const isProxyActive = await detectProxy();
    console.log('Proxy is active:', isProxyActive);
  } catch (error) {
    console.error('Failed to detect proxy:', error);
  }
}
```

### Check Both VPN and Proxy

```js
import { detectVPN, detectProxy } from 'react-native-vpn-proxy-detect';

async function checkNetworkSecurity() {
  try {
    const [vpnResult, proxyResult] = await Promise.all([
      detectVPN(),
      detectProxy()
    ]);
    
    console.log('VPN Status:', vpnResult ? 'Active' : 'Inactive');
    console.log('Proxy Status:', proxyResult ? 'Active' : 'Inactive');
  } catch (error) {
    console.error('Failed to detect network status:', error);
  }
}
```

### Using Default Export (Backward Compatibility)

```js
import VpnProxyDetect from 'react-native-vpn-proxy-detect';

async function checkSecurity() {
  try {
    const vpnActive = await VpnProxyDetect.detectVPN();
    const proxyActive = await VpnProxyDetect.detectProxy();
    
    console.log('VPN:', vpnActive);
    console.log('Proxy:', proxyActive);
  } catch (error) {
    console.error('Detection failed:', error);
  }
}
```

## API Reference

### `detectVPN(): Promise<boolean>`

Detects if a VPN connection is currently active.

**Returns:** Promise that resolves to `true` if VPN is active, `false` otherwise.

**Throws:** Error if detection fails.

### `detectProxy(): Promise<boolean>`

Detects if a proxy connection is currently active.

**Returns:** Promise that resolves to `true` if proxy is active, `false` otherwise.

**Throws:** Error if detection fails.

## Platform-Specific Implementation

### iOS
- Uses `CFNetworkCopySystemProxySettings()` to detect VPN connections by checking for network interfaces like `tap`, `tun`, `ppp`, `ipsec`, and `utun`
- Uses `CFNetworkCopyProxiesForURL()` to detect proxy settings

### Android  
- Uses `ConnectivityManager` and `NetworkCapabilities` to detect VPN connections
- Checks system properties for proxy configuration

## Example App

The library includes a complete example app demonstrating all features. To run it:

```sh
# Install dependencies
yarn

# Run on iOS
yarn example ios

# Run on Android  
yarn example android
```

## Migration from react-native-vpn-detect

This library is a modernized version of `react-native-vpn-detect` with the following improvements:

- **New import syntax**: Use named imports instead of default export
- **Turbo Module**: Better performance and future-proof architecture
- **TypeScript**: Full TypeScript support out of the box
- **Modern tooling**: Latest React Native development tools

### Migration Guide

**Old usage:**
```js
import Security from "react-native-vpn-detect";

const vpnActive = await Security.detectVPN();
const proxyActive = await Security.detectProxy();
```

**New usage:**
```js
import { detectVPN, detectProxy } from 'react-native-vpn-proxy-detect';

const vpnActive = await detectVPN();
const proxyActive = await detectProxy();
```

## Contributing

- [Development workflow](CONTRIBUTING.md#development-workflow)
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
- [Code of conduct](CODE_OF_CONDUCT.md)

## License

MIT

---

Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)