Skip to content

Commit ad7686f

Browse files
committed
✨ feat: support get vpn status
1 parent 0aa7a33 commit ad7686f

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

android/src/main/java/com/norcod/rnovpn/RNSimpleOpenvpnModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ public void disconnect(Promise promise) {
194194
}
195195
}
196196

197+
@ReactMethod
198+
public void getCurrentState(Promise promise) {
199+
promise.resolve(getVpnState(VpnStatus.getStatus()));
200+
}
201+
197202
private void prepareVpn(final Promise promise) {
198203
Activity currentActivity = getCurrentActivity();
199204

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ interface VpnEventParams {
4242
declare namespace RNSimpleOpenvpn {
4343
function connect(options: VpnOptions): Promise<void>;
4444
function disconnect(): Promise<void>;
45+
function getCurrentState(): Promise<VpnState>;
4546
function observeState(): Promise<void>;
4647
function stopObserveState(): Promise<void>;
4748
enum VpnState {

ios/RNSimpleOpenvpn.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ - (void)startVpn:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock
177177
resolve(nil);
178178
}
179179

180+
RCT_EXPORT_METHOD(getCurrentState : (RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)reject) {
181+
NSDictionary *vpnState = [self getVpnState:self.providerManager.connection.status];
182+
resolve(vpnState[@"state"]);
183+
}
184+
180185
- (NSDictionary *)getVpnState:(NEVPNStatus)status {
181186
VpnState state;
182187
NSString *message;

vpnLib/src/main/java/de/blinkt/openvpn/core/VpnStatus.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public static boolean isVPNActive() {
7373
return mLastLevel != ConnectionStatus.LEVEL_AUTH_FAILED && !(mLastLevel == ConnectionStatus.LEVEL_NOTCONNECTED);
7474
}
7575

76+
public static ConnectionStatus getStatus() {
77+
return mLastLevel;
78+
}
79+
7680
public static String getLastCleanLogMessage(Context c) {
7781
String message = mLaststatemsg;
7882
switch (mLastLevel) {

0 commit comments

Comments
 (0)