From 60decf769284d9e655dde0fd7a5836730741fb39 Mon Sep 17 00:00:00 2001 From: hristoterezov Date: Wed, 26 Sep 2018 12:57:58 -0500 Subject: [PATCH] ref(dropbox): Consistency for the naming around the app key. --- android/app/build.gradle | 10 +- .../org/jitsi/meet/sdk/dropbox/Dropbox.java | 193 +++++++++--------- config.js | 2 +- react/features/dropbox/actions.js | 2 +- react/features/dropbox/functions.any.js | 6 +- react/features/dropbox/functions.native.js | 25 ++- react/features/dropbox/functions.web.js | 95 +++++---- .../Recording/StartRecordingDialog.js | 12 +- 8 files changed, 173 insertions(+), 172 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index a70b657d6..261bfb5e9 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.application' -def dropboxAppID = "" +def dropboxAppKey = "" android { compileSdkVersion rootProject.ext.compileSdkVersion @@ -30,12 +30,12 @@ android { buildTypes { debug { - resValue("string", "dropbox_app_key", "${dropboxAppID}") + resValue("string", "dropbox_app_key", "${dropboxAppKey}") minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-debug.pro' } release { - resValue("string", "dropbox_app_key", "${dropboxAppID}") + resValue("string", "dropbox_app_key", "${dropboxAppKey}") minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-release.pro' } @@ -46,13 +46,13 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } - if (dropboxAppID) { + if (dropboxAppKey) { def dropboxActivity = """ - + diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/dropbox/Dropbox.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/dropbox/Dropbox.java index 10c25db8e..e2c558218 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/dropbox/Dropbox.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/dropbox/Dropbox.java @@ -1,12 +1,10 @@ package org.jitsi.meet.sdk.dropbox; -import android.app.Activity; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.text.TextUtils; -import android.util.Log; import com.dropbox.core.DbxException; import com.dropbox.core.DbxRequestConfig; @@ -22,7 +20,6 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.dropbox.core.android.Auth; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.WritableMap; -import org.jitsi.meet.sdk.R; import java.util.HashMap; import java.util.Map; @@ -30,26 +27,28 @@ import java.util.Map; /** * Implements the react-native module for the dropbox integration. */ -public class Dropbox extends ReactContextBaseJavaModule implements LifecycleEventListener { +public class Dropbox + extends ReactContextBaseJavaModule + implements LifecycleEventListener { + private String appKey; - private Promise promise = null; private String clientId; - private String appID; - private boolean isEnabled = false; + + private final boolean isEnabled; + + private Promise promise; public Dropbox(ReactApplicationContext reactContext) { super(reactContext); - reactContext.addLifecycleEventListener(this); - clientId = generateClientId(); - appID = reactContext.getString(R.string.dropbox_app_key); - if (!TextUtils.isEmpty(appID)) { - isEnabled = true; - } - } - @Override - public String getName() { - return "Dropbox"; + appKey + = reactContext.getString( + org.jitsi.meet.sdk.R.string.dropbox_app_key); + isEnabled = !TextUtils.isEmpty(appKey); + + clientId = generateClientId(); + + reactContext.addLifecycleEventListener(this); } /** @@ -59,70 +58,12 @@ public class Dropbox extends ReactContextBaseJavaModule implements LifecycleEven */ @ReactMethod public void authorize(final Promise promise) { - if (!isEnabled) { - promise.reject(new Exception("Dropbox integration isn't configured.")); - return; - } - Auth.startOAuth2Authentication(this.getCurrentActivity(), appID); - this.promise = promise; - } - - @Override - public Map getConstants() { - final Map constants = new HashMap<>(); - constants.put("ENABLED", isEnabled); - return constants; - } - - - /** - * Resolves the current user dropbox display name. - * - * @param token A dropbox access token. - * @param promise The promise used to return the result of the auth flow. - */ - @ReactMethod - public void getDisplayName(final String token, final Promise promise) { - DbxRequestConfig config - = DbxRequestConfig.newBuilder(clientId).build(); - DbxClientV2 client = new DbxClientV2(config, token); - // Get current account info - try { - FullAccount account = client.users().getCurrentAccount(); - promise.resolve(account.getName().getDisplayName()); - } catch (DbxException e) { - promise.reject(e); - } - } - - /** - * Resolves the current user space usage. - * - * @param token A dropbox access token. - * @param promise The promise used to return the result of the auth flow. - */ - @ReactMethod - public void getSpaceUsage(final String token, final Promise promise) { - DbxRequestConfig config - = DbxRequestConfig.newBuilder(clientId).build(); - DbxClientV2 client = new DbxClientV2(config, token); - try { - SpaceUsage spaceUsage = client.users().getSpaceUsage(); - WritableMap map = Arguments.createMap(); - map.putString("used", String.valueOf(spaceUsage.getUsed())); - SpaceAllocation allocation = spaceUsage.getAllocation(); - long allocated = 0; - if(allocation.isIndividual()) { - allocated += allocation.getIndividualValue().getAllocated(); - } - - if(allocation.isTeam()) { - allocated += allocation.getTeamValue().getAllocated(); - } - map.putString("allocated", String.valueOf(allocated)); - promise.resolve(map); - } catch (DbxException e) { - promise.reject(e); + if (isEnabled) { + Auth.startOAuth2Authentication(this.getCurrentActivity(), appKey); + this.promise = promise; + } else { + promise.reject( + new Exception("Dropbox integration isn't configured.")); } } @@ -141,8 +82,7 @@ public class Dropbox extends ReactContextBaseJavaModule implements LifecycleEven try { String packageName = context.getPackageName(); - applicationInfo - = packageManager.getApplicationInfo(packageName, 0); + applicationInfo = packageManager.getApplicationInfo(packageName, 0); packageInfo = packageManager.getPackageInfo(packageName, 0); } catch (PackageManager.NameNotFoundException e) { } @@ -150,32 +90,95 @@ public class Dropbox extends ReactContextBaseJavaModule implements LifecycleEven String applicationLabel = applicationInfo == null ? "JitsiMeet" - : packageManager.getApplicationLabel(applicationInfo) - .toString().replaceAll("\\s", ""); + : packageManager.getApplicationLabel(applicationInfo).toString() + .replaceAll("\\s", ""); String version = packageInfo == null ? "dev" : packageInfo.versionName; - return applicationLabel + "/" + version; + return applicationLabel + "/" + version; } @Override - public void onHostResume() { - final String token = Auth.getOAuth2Token(); - if (token == null) - return; + public Map getConstants() { + Map constants = new HashMap<>(); - if (this.promise != null) { - this.promise.resolve(token); - this.promise = null; + constants.put("ENABLED", isEnabled); + + return constants; + } + + /** + * Resolves the current user dropbox display name. + * + * @param token A dropbox access token. + * @param promise The promise used to return the result of the auth flow. + */ + @ReactMethod + public void getDisplayName(final String token, final Promise promise) { + DbxRequestConfig config = DbxRequestConfig.newBuilder(clientId).build(); + DbxClientV2 client = new DbxClientV2(config, token); + + // Get current account info + try { + FullAccount account = client.users().getCurrentAccount(); + + promise.resolve(account.getName().getDisplayName()); + } catch (DbxException e) { + promise.reject(e); } } @Override - public void onHostPause() { + public String getName() { + return "Dropbox"; + } + /** + * Resolves the current user space usage. + * + * @param token A dropbox access token. + * @param promise The promise used to return the result of the auth flow. + */ + @ReactMethod + public void getSpaceUsage(final String token, final Promise promise) { + DbxRequestConfig config = DbxRequestConfig.newBuilder(clientId).build(); + DbxClientV2 client = new DbxClientV2(config, token); + + try { + SpaceUsage spaceUsage = client.users().getSpaceUsage(); + WritableMap map = Arguments.createMap(); + + map.putString("used", String.valueOf(spaceUsage.getUsed())); + + SpaceAllocation allocation = spaceUsage.getAllocation(); + long allocated = 0; + + if (allocation.isIndividual()) { + allocated += allocation.getIndividualValue().getAllocated(); + } + if (allocation.isTeam()) { + allocated += allocation.getTeamValue().getAllocated(); + } + map.putString("allocated", String.valueOf(allocated)); + + promise.resolve(map); + } catch (DbxException e) { + promise.reject(e); + } } @Override - public void onHostDestroy() { + public void onHostDestroy() {} + @Override + public void onHostPause() {} + + @Override + public void onHostResume() { + String token = Auth.getOAuth2Token(); + + if (token != null && this.promise != null) { + this.promise.resolve(token); + this.promise = null; + } } } diff --git a/config.js b/config.js index 90e43105c..f816b1832 100644 --- a/config.js +++ b/config.js @@ -173,7 +173,7 @@ var config = { // fileRecordingsEnabled: false, // Enable the dropbox integration. // dropbox: { - // clientId: '' // Specify your app ID here. + // appKey: '' // Specify your app key here. // }, // Whether to enable live streaming or not. diff --git a/react/features/dropbox/actions.js b/react/features/dropbox/actions.js index edca7c800..431db59a6 100644 --- a/react/features/dropbox/actions.js +++ b/react/features/dropbox/actions.js @@ -18,7 +18,7 @@ export function authorizeDropbox() { const redirectURI = `${locationURL.origin + getLocationContextRoot(locationURL)}static/oauth.html`; - _authorizeDropbox(dropbox.clientId, redirectURI) + _authorizeDropbox(dropbox.appKey, redirectURI) .then( token => dispatch(updateDropboxToken(token))); }; diff --git a/react/features/dropbox/functions.any.js b/react/features/dropbox/functions.any.js index 8d0f824ed..388f31dab 100644 --- a/react/features/dropbox/functions.any.js +++ b/react/features/dropbox/functions.any.js @@ -25,15 +25,15 @@ type DropboxUserData = { * Fetches information about the user's dropbox account. * * @param {string} token - The dropbox access token. - * @param {string} clientId - The Jitsi Recorder dropbox app ID. + * @param {string} appKey - The Jitsi Recorder dropbox app key. * @returns {Promise} */ export function getDropboxData( token: string, - clientId: string + appKey: string ): Promise { return Promise.all( - [ getDisplayName(token, clientId), getSpaceUsage(token, clientId) ] + [ getDisplayName(token, appKey), getSpaceUsage(token, appKey) ] ).then(([ userName, space ]) => { const { allocated, used } = space; diff --git a/react/features/dropbox/functions.native.js b/react/features/dropbox/functions.native.js index 593d64ca8..ccfeecf98 100644 --- a/react/features/dropbox/functions.native.js +++ b/react/features/dropbox/functions.native.js @@ -4,6 +4,18 @@ import { NativeModules } from 'react-native'; const { Dropbox } = NativeModules; +/** + * Action to authorize the Jitsi Recording app in dropbox. + * + * @param {string} appKey - The Jitsi Recorder dropbox app key. + * @param {string} redirectURI - The return URL. + * @returns {Promise} - The promise will be resolved with the dropbox + * access token or rejected with an error. + */ +export function _authorizeDropbox(): Promise { + return Dropbox.authorize(); +} + /** * Returns the display name for the current dropbox account. * @@ -28,19 +40,6 @@ export function getSpaceUsage(token: string) { return Dropbox.getSpaceUsage(token); } - -/** - * Action to authorize the Jitsi Recording app in dropbox. - * - * @param {string} clientId - The Jitsi Recorder dropbox app ID. - * @param {string} redirectURI - The return URL. - * @returns {Promise} - The promise will be resolved with the dropbox - * access token or rejected with an error. - */ -export function _authorizeDropbox(): Promise { - return Dropbox.authorize(); -} - /** * Returns true if the dropbox features is enabled and false * otherwise. diff --git a/react/features/dropbox/functions.web.js b/react/features/dropbox/functions.web.js index 07fbf8743..244060e7b 100644 --- a/react/features/dropbox/functions.web.js +++ b/react/features/dropbox/functions.web.js @@ -2,54 +2,11 @@ import { Dropbox } from 'dropbox'; +import { parseURLParams } from '../base/config'; import { getJitsiMeetGlobalNS, parseStandardURIString } from '../base/util'; -import { parseURLParams } from '../base/config'; - -/** - * Returns the display name for the current dropbox account. - * - * @param {string} token - The dropbox access token. - * @param {string} clientId - The Jitsi Recorder dropbox app ID. - * @returns {Promise} - */ -export function getDisplayName(token: string, clientId: string) { - const dropboxAPI = new Dropbox({ - accessToken: token, - clientId - }); - - return ( - dropboxAPI.usersGetCurrentAccount() - .then(account => account.name.display_name)); -} - -/** - * Returns information about the space usage for the current dropbox account. - * - * @param {string} token - The dropbox access token. - * @param {string} clientId - The Jitsi Recorder dropbox app ID. - * @returns {Promise} - */ -export function getSpaceUsage(token: string, clientId: string) { - const dropboxAPI = new Dropbox({ - accessToken: token, - clientId - }); - - return dropboxAPI.usersGetSpaceUsage().then(space => { - const { allocation, used } = space; - const { allocated } = allocation; - - return { - used, - allocated - }; - }); -} - /** * Executes the oauth flow. @@ -79,15 +36,15 @@ function authorize(authUrl: string): Promise { /** * Action to authorize the Jitsi Recording app in dropbox. * - * @param {string} clientId - The Jitsi Recorder dropbox app ID. + * @param {string} appKey - The Jitsi Recorder dropbox app key. * @param {string} redirectURI - The return URL. * @returns {Promise} */ export function _authorizeDropbox( - clientId: string, + appKey: string, redirectURI: string ): Promise { - const dropboxAPI = new Dropbox({ clientId }); + const dropboxAPI = new Dropbox({ clientId: appKey }); const url = dropboxAPI.getAuthenticationUrl(redirectURI); return authorize(url).then(returnUrl => { @@ -98,6 +55,48 @@ export function _authorizeDropbox( }); } +/** + * Returns the display name for the current dropbox account. + * + * @param {string} token - The dropbox access token. + * @param {string} appKey - The Jitsi Recorder dropbox app key. + * @returns {Promise} + */ +export function getDisplayName(token: string, appKey: string) { + const dropboxAPI = new Dropbox({ + accessToken: token, + clientId: appKey + }); + + return ( + dropboxAPI.usersGetCurrentAccount() + .then(account => account.name.display_name)); +} + +/** + * Returns information about the space usage for the current dropbox account. + * + * @param {string} token - The dropbox access token. + * @param {string} appKey - The Jitsi Recorder dropbox app key. + * @returns {Promise} + */ +export function getSpaceUsage(token: string, appKey: string) { + const dropboxAPI = new Dropbox({ + accessToken: token, + clientId: appKey + }); + + return dropboxAPI.usersGetSpaceUsage().then(space => { + const { allocation, used } = space; + const { allocated } = allocation; + + return { + allocated, + used + }; + }); +} + /** * Returns true if the dropbox features is enabled and false * otherwise. @@ -108,5 +107,5 @@ export function _authorizeDropbox( export function isEnabled(state: Object) { const { dropbox = {} } = state['features/base/config']; - return typeof dropbox.clientId === 'string'; + return typeof dropbox.appKey === 'string'; } diff --git a/react/features/recording/components/Recording/StartRecordingDialog.js b/react/features/recording/components/Recording/StartRecordingDialog.js index 720497b4e..3a3ce9440 100644 --- a/react/features/recording/components/Recording/StartRecordingDialog.js +++ b/react/features/recording/components/Recording/StartRecordingDialog.js @@ -21,9 +21,9 @@ type Props = { _conference: Object, /** - * The client id for the dropbox authentication. + * The app key for the dropbox authentication. */ - _clientId: string, + _appKey: string, /** * The dropbox access token. @@ -117,7 +117,7 @@ class StartRecordingDialog extends Component { * @returns {void} */ _onTokenUpdated() { - const { _clientId, _token } = this.props; + const { _appKey, _token } = this.props; if (typeof _token === 'undefined') { this.setState({ @@ -129,7 +129,7 @@ class StartRecordingDialog extends Component { isTokenValid: false, isValidating: true }); - getDropboxData(_token, _clientId).then(data => { + getDropboxData(_token, _appKey).then(data => { if (typeof data === 'undefined') { this.setState({ isTokenValid: false, @@ -216,7 +216,7 @@ class StartRecordingDialog extends Component { * @param {Object} state - The Redux state. * @private * @returns {{ - * _clientId: string, + * _appKey: string, * _conference: JitsiConference, * _token: string * }} @@ -225,7 +225,7 @@ function mapStateToProps(state: Object) { const { dropbox = {} } = state['features/base/config']; return { - _clientId: dropbox.clientId, + _appKey: dropbox.appKey, _conference: state['features/base/conference'].conference, _token: state['features/dropbox'].token };