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.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // @flow
  2. import { Dropbox } from 'dropbox';
  3. import { JitsiRecordingConstants } from '../base/lib-jitsi-meet';
  4. /**
  5. * Searches in the passed in redux state for an active recording session of the
  6. * passed in mode.
  7. *
  8. * @param {Object} state - The redux state to search in.
  9. * @param {string} mode - Find an active recording session of the given mode.
  10. * @returns {Object|undefined}
  11. */
  12. export function getActiveSession(state: Object, mode: string) {
  13. const { sessionDatas } = state['features/recording'];
  14. const { status: statusConstants } = JitsiRecordingConstants;
  15. return sessionDatas.find(sessionData => sessionData.mode === mode
  16. && (sessionData.status === statusConstants.ON
  17. || sessionData.status === statusConstants.PENDING));
  18. }
  19. /**
  20. * Searches in the passed in redux state for a recording session that matches
  21. * the passed in recording session ID.
  22. *
  23. * @param {Object} state - The redux state to search in.
  24. * @param {string} id - The ID of the recording session to find.
  25. * @returns {Object|undefined}
  26. */
  27. export function getSessionById(state: Object, id: string) {
  28. return state['features/recording'].sessionDatas.find(
  29. sessionData => sessionData.id === id);
  30. }
  31. /**
  32. * Fetches information about the user's dropbox account.
  33. *
  34. * @param {string} token - The dropbox access token.
  35. * @param {string} clientId - The Jitsi Recorder dropbox app ID.
  36. * @returns {Promise<Object|undefined>}
  37. */
  38. export function getDropboxData(
  39. token: string,
  40. clientId: string
  41. ): Promise<?Object> {
  42. const dropboxAPI = new Dropbox({
  43. accessToken: token,
  44. clientId
  45. });
  46. return Promise.all(
  47. [ dropboxAPI.usersGetCurrentAccount(), dropboxAPI.usersGetSpaceUsage() ]
  48. ).then(([ account, space ]) => {
  49. const { allocation, used } = space;
  50. const { allocated } = allocation;
  51. return {
  52. userName: account.name.display_name,
  53. spaceLeft: Math.floor((allocated - used) / 1048576)// 1MiB=1048576B
  54. };
  55. }, () => undefined);
  56. }