You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.native.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // @flow
  2. import { NativeModules } from 'react-native';
  3. const { Dropbox } = NativeModules;
  4. import { setPictureInPictureDisabled } from '../mobile/picture-in-picture/functions';
  5. /**
  6. * Action to authorize the Jitsi Recording app in dropbox.
  7. *
  8. * @returns {Promise<Object>} - The promise will be resolved with the dropbox
  9. * access token or rejected with an error.
  10. */
  11. export async function _authorizeDropbox(): Promise<Object> {
  12. setPictureInPictureDisabled(true);
  13. try {
  14. return await Dropbox.authorize();
  15. } finally {
  16. setPictureInPictureDisabled(false);
  17. }
  18. }
  19. /**
  20. * Gets a new acccess token based on the refresh token.
  21. *
  22. * @returns {Promise}
  23. */
  24. export function getNewAccessToken() {
  25. return _authorizeDropbox();
  26. }
  27. /**
  28. * Returns the display name for the current dropbox account.
  29. *
  30. * @param {string} token - The dropbox access token.
  31. * @returns {Promise<string>} - The promise will be resolved with the display
  32. * name or rejected with an error.
  33. */
  34. export function getDisplayName(token: string) {
  35. return Dropbox.getDisplayName(token);
  36. }
  37. /**
  38. * Returns information about the space usage for the current dropbox account.
  39. *
  40. * @param {string} token - The dropbox access token.
  41. * @returns {Promise<{ used: number, allocated: number}>} - The promise will be
  42. * resolved with the object with information about the space usage (the used
  43. * space and the allocated space) for the current dropbox account or rejected
  44. * with an error.
  45. */
  46. export function getSpaceUsage(token: string) {
  47. return Dropbox.getSpaceUsage(token);
  48. }
  49. /**
  50. * Returns <tt>true</tt> if the dropbox features is enabled and <tt>false</tt>
  51. * otherwise.
  52. *
  53. * @param {Object} state - The redux state.
  54. * @returns {boolean}
  55. */
  56. export function isEnabled(state: Object) {
  57. const { dropbox = {} } = state['features/base/config'];
  58. return Dropbox.ENABLED && typeof dropbox.appKey === 'string';
  59. }