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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // @flow
  2. import { JitsiRecordingConstants } from '../base/lib-jitsi-meet';
  3. import { RECORDING_STATUS_PRIORITIES } from './constants';
  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. * Returns an estimated recording duration based on the size of the video file
  21. * in MB. The estimate is calculated under the assumption that 1 min of recorded
  22. * video needs 10MB of storage on avarage.
  23. *
  24. * @param {number} size - The size in MB of the recorded video.
  25. * @returns {number} - The estimated duration in minutes.
  26. */
  27. export function getRecordingDurationEstimation(size: ?number) {
  28. return Math.floor((size || 0) / 10);
  29. }
  30. /**
  31. * Searches in the passed in redux state for a recording session that matches
  32. * the passed in recording session ID.
  33. *
  34. * @param {Object} state - The redux state to search in.
  35. * @param {string} id - The ID of the recording session to find.
  36. * @returns {Object|undefined}
  37. */
  38. export function getSessionById(state: Object, id: string) {
  39. return state['features/recording'].sessionDatas.find(
  40. sessionData => sessionData.id === id);
  41. }
  42. /**
  43. * Returns the recording session status that is to be shown in a label. E.g. If
  44. * there is a session with the status OFF and one with PENDING, then the PENDING
  45. * one will be shown, because that is likely more important for the user to see.
  46. *
  47. * @param {Object} state - The redux state to search in.
  48. * @param {string} mode - The recording mode to get status for.
  49. * @returns {string|undefined}
  50. */
  51. export function getSessionStatusToShow(state: Object, mode: string): ?string {
  52. const recordingSessions = state['features/recording'].sessionDatas;
  53. let status;
  54. if (Array.isArray(recordingSessions)) {
  55. for (const session of recordingSessions) {
  56. if (session.mode === mode
  57. && (!status
  58. || (RECORDING_STATUS_PRIORITIES.indexOf(session.status)
  59. > RECORDING_STATUS_PRIORITIES.indexOf(status)))) {
  60. status = session.status;
  61. }
  62. }
  63. }
  64. return status;
  65. }