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.ts 2.3KB

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