ref(dropbox): Consistency for the naming around the app key.

This commit is contained in:
hristoterezov 2018-09-26 12:57:58 -05:00 committed by Любомир Маринов
parent 467452d110
commit 60decf7692
8 changed files with 173 additions and 172 deletions

View File

@ -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 = """<activity
android:name="com.dropbox.core.android.AuthActivity"
android:configChanges="orientation|keyboard"
android:launchMode="singleTask">
<intent-filter>
<data android:scheme="db-${dropboxAppID}" />
<data android:scheme="db-${dropboxAppKey}" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />

View File

@ -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<String, Object> getConstants() {
final Map<String, Object> 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<String, Object> getConstants() {
Map<String, Object> 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;
}
}
}

View File

@ -173,7 +173,7 @@ var config = {
// fileRecordingsEnabled: false,
// Enable the dropbox integration.
// dropbox: {
// clientId: '<APP_ID>' // Specify your app ID here.
// appKey: '<APP_KEY>' // Specify your app key here.
// },
// Whether to enable live streaming or not.

View File

@ -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)));
};

View File

@ -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<DropboxUserData|undefined>}
*/
export function getDropboxData(
token: string,
clientId: string
appKey: string
): Promise<?DropboxUserData> {
return Promise.all(
[ getDisplayName(token, clientId), getSpaceUsage(token, clientId) ]
[ getDisplayName(token, appKey), getSpaceUsage(token, appKey) ]
).then(([ userName, space ]) => {
const { allocated, used } = space;

View File

@ -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<string>} - The promise will be resolved with the dropbox
* access token or rejected with an error.
*/
export function _authorizeDropbox(): Promise<string> {
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<string>} - The promise will be resolved with the dropbox
* access token or rejected with an error.
*/
export function _authorizeDropbox(): Promise<string> {
return Dropbox.authorize();
}
/**
* Returns <tt>true</tt> if the dropbox features is enabled and <tt>false</tt>
* otherwise.

View File

@ -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<string>}
*/
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<Object>}
*/
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<string> {
/**
* 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<string>}
*/
export function _authorizeDropbox(
clientId: string,
appKey: string,
redirectURI: string
): Promise<string> {
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<string>}
*/
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<Object>}
*/
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 <tt>true</tt> if the dropbox features is enabled and <tt>false</tt>
* 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';
}

View File

@ -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<Props, State> {
* @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<Props, State> {
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<Props, State> {
* @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
};