diff --git a/client/src/cordova/plugin/android/java/org/outline/OutlinePlugin.java b/client/src/cordova/plugin/android/java/org/outline/OutlinePlugin.java index 03cc6f75ef..c185e00d87 100644 --- a/client/src/cordova/plugin/android/java/org/outline/OutlinePlugin.java +++ b/client/src/cordova/plugin/android/java/org/outline/OutlinePlugin.java @@ -42,6 +42,8 @@ import org.outline.vpn.Errors; import org.outline.vpn.VpnServiceStarter; import org.outline.vpn.VpnTunnelService; +import outline.Outline; +import outline.FetchDynamicKeyResult; import platerrors.Platerrors; import platerrors.PlatformError; @@ -57,6 +59,7 @@ public enum Action { STOP("stop"), ON_STATUS_CHANGE("onStatusChange"), IS_RUNNING("isRunning"), + FETCH_CONFIG("fetchConfig"), INIT_ERROR_REPORTING("initializeErrorReporting"), REPORT_EVENTS("reportEvents"), QUIT("quitApplication"); @@ -202,6 +205,17 @@ private void executeAsync( final String tunnelId = args.getString(0); boolean isActive = isTunnelActive(tunnelId); callback.sendPluginResult(new PluginResult(PluginResult.Status.OK, isActive)); + } else if (Action.FETCH_CONFIG.is(action)) { + final String url = args.getString(0); + LOG.fine(String.format(Locale.ROOT, "Fetching dynamic config at %s ...", url)); + final FetchDynamicKeyResult result = Outline.fetchDynamicKey(url); + if (result.getError() != null) { + LOG.warning(String.format(Locale.ROOT, "Fetch dynamic config failed: %s", result.getError())); + sendActionResult(callback, result.getError()); + } else { + LOG.info(String.format(Locale.ROOT, "Fetch dynamic config result: %s", result.getKey())); + callback.success(result.getKey()); + } // Static actions } else if (Action.INIT_ERROR_REPORTING.is(action)) { diff --git a/client/src/www/app/outline_server_repository/vpn.cordova.ts b/client/src/www/app/outline_server_repository/vpn.cordova.ts index 04d1d8e475..bd6f6f568e 100644 --- a/client/src/www/app/outline_server_repository/vpn.cordova.ts +++ b/client/src/www/app/outline_server_repository/vpn.cordova.ts @@ -51,20 +51,24 @@ export class CordovaVpnApi implements VpnApi { cordova.exec(callback, onError, OUTLINE_PLUGIN_NAME, 'onStatusChange', []); } - // TODO: move to Go fetch implementation later async fetchDynamicConfig(url: string): Promise { - let response: Response; - try { - response = await fetch(url, { - cache: 'no-store', - redirect: 'follow', - }); - } catch (cause) { - throw new errors.SessionConfigFetchFailed( - 'Failed to fetch VPN information from dynamic access key.', - {cause} - ); + if (cordova.platformId === 'android') { + return pluginExecWithErrorCode('fetchConfig', url); + } else { + // TODO: move to Go fetch implementation later + let response: Response; + try { + response = await fetch(url, { + cache: 'no-store', + redirect: 'follow', + }); + } catch (cause) { + throw new errors.SessionConfigFetchFailed( + 'Failed to fetch VPN information from dynamic access key.', + {cause} + ); + } + return (await response.text()).trim(); } - return (await response.text()).trim(); } }