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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { NativeModules } from 'react-native';
  2. import { IReduxState } from '../app/types';
  3. // eslint-disable-next-line lines-around-comment
  4. // @ts-ignore
  5. import { setPictureInPictureEnabled } from '../mobile/picture-in-picture/functions';
  6. const { Dropbox } = NativeModules;
  7. /**
  8. * Action to authorize the Jitsi Recording app in dropbox.
  9. *
  10. * @param {any} _appKey - Used on web.
  11. * @param {any} _redirectURI - Used on web.
  12. * @returns {Promise<Object>} - The promise will be resolved with the dropbox
  13. * access token or rejected with an error.
  14. */
  15. export async function _authorizeDropbox(_appKey?: any, _redirectURI?: any): Promise<any> {
  16. setPictureInPictureEnabled(false);
  17. try {
  18. return await Dropbox.authorize();
  19. } finally {
  20. setPictureInPictureEnabled(true);
  21. }
  22. }
  23. /**
  24. * Gets a new access token based on the refresh token.
  25. *
  26. * @returns {Promise}
  27. */
  28. export function getNewAccessToken() {
  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 = {} } = state['features/base/config'];
  64. // @ts-ignore
  65. return Boolean(Dropbox?.ENABLED && typeof dropbox.appKey === 'string');
  66. }