react-native-wireguard
Getting started
$ npm install react-native-wireguard --save
Mostly automatic installation
$ react-native link react-native-wireguard
iOS
Doesn't work on iOS yet. SOON...
Android
- Insert the following service lines to your
AndroidManifest.xml
:
<application>
....
<service
android:name="com.wirevpn.rnwireguard.WGVpnService"
android:permission="android.permission.BIND_VPN_SERVICE">
<intent-filter>
<action android:name="android.net.VpnService" />
</intent-filter>
</service>
....
</application>
- Insert your notification area icon(s) to
res/drawable
or to its multiple hidpi counterparts. - Insert your
applicationId
to the top level build.gradle
to have it accessible.
buildscript {
....
ext {
minSdkVersion = 21
targetSdkVersion = 26
compileSdkVersion = 28
....
applicationId = "com.wirevpn.android"
}
....
}
Usage
import WireGuard from 'react-native-wireguard';
WireGuard.Version().then((v) => this.setState{version: v});
var config = `
[Interface]
PrivateKey = mBEJJwnMh6Ht9xLp88nTtHqmOY9pnN7YdriotquvgVI=
Address = 192.168.7.237/32, fdaa::7f3/128
DNS = 192.168.0.0, fdaa::
[Peer]
PublicKey = Cf0rdfToO5gxg7ObB6dLbTwfElO3Xx7Fh8jJobmqCnE=
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = 209.97.177.222:51820`;
var session = 'MyVPNSession';
var notif = {
icon: 'ic_notif_icon',
title: 'My VPN',
text: 'Connected to ' + country;
}
WireGuard.Connect(config, session, notif).catch(
(e) => console.warn(e.message));
WireGuard.Status().then((b) => {
if(b){
}
});
WireGuard.Disconnect()
componentDidMount() {
DeviceEventEmitter.addListener(WireGuard.EV_TYPE_SYSTEM, () => {
if(e === WireGuard.EV_STARTED_BY_SYSTEM) {
}
});
DeviceEventEmitter.addListener(WireGuard.EV_TYPE_EXCEPTION, () => {
console.log(e);
});
DeviceEventEmitter.addListener(WireGuard.EV_TYPE_REGULAR, () => {
if(e === WireGuard.EV_STOPPED) {
} else if(e === WireGuard.EV_STARTED) {
}
});
}
componentWillUnmount() {
DeviceEventEmitter.removeAllListeners();
}