File tree Expand file tree Collapse file tree 4 files changed +15
-0
lines changed
android/src/main/java/com/norcod/rnovpn
vpnLib/src/main/java/de/blinkt/openvpn/core Expand file tree Collapse file tree 4 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -194,6 +194,11 @@ public void disconnect(Promise promise) {
194
194
}
195
195
}
196
196
197
+ @ ReactMethod
198
+ public void getCurrentState (Promise promise ) {
199
+ promise .resolve (getVpnState (VpnStatus .getStatus ()));
200
+ }
201
+
197
202
private void prepareVpn (final Promise promise ) {
198
203
Activity currentActivity = getCurrentActivity ();
199
204
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ interface VpnEventParams {
42
42
declare namespace RNSimpleOpenvpn {
43
43
function connect ( options : VpnOptions ) : Promise < void > ;
44
44
function disconnect ( ) : Promise < void > ;
45
+ function getCurrentState ( ) : Promise < VpnState > ;
45
46
function observeState ( ) : Promise < void > ;
46
47
function stopObserveState ( ) : Promise < void > ;
47
48
enum VpnState {
Original file line number Diff line number Diff line change @@ -177,6 +177,11 @@ - (void)startVpn:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock
177
177
resolve (nil );
178
178
}
179
179
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
+
180
185
- (NSDictionary *)getVpnState : (NEVPNStatus)status {
181
186
VpnState state;
182
187
NSString *message;
Original file line number Diff line number Diff line change @@ -73,6 +73,10 @@ public static boolean isVPNActive() {
73
73
return mLastLevel != ConnectionStatus .LEVEL_AUTH_FAILED && !(mLastLevel == ConnectionStatus .LEVEL_NOTCONNECTED );
74
74
}
75
75
76
+ public static ConnectionStatus getStatus () {
77
+ return mLastLevel ;
78
+ }
79
+
76
80
public static String getLastCleanLogMessage (Context c ) {
77
81
String message = mLaststatemsg ;
78
82
switch (mLastLevel ) {
You can’t perform that action at this time.
0 commit comments