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 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // @flow
  2. import { JitsiRecordingConstants } from '../base/lib-jitsi-meet';
  3. import { isEnabled as isDropboxEnabled } from '../dropbox';
  4. import { RECORDING_STATUS_PRIORITIES, RECORDING_TYPES } from './constants';
  5. /**
  6. * Searches in the passed in redux state for an active recording session of the
  7. * passed in mode.
  8. *
  9. * @param {Object} state - The redux state to search in.
  10. * @param {string} mode - Find an active recording session of the given mode.
  11. * @returns {Object|undefined}
  12. */
  13. export function getActiveSession(state: Object, mode: string) {
  14. const { sessionDatas } = state['features/recording'];
  15. const { status: statusConstants } = JitsiRecordingConstants;
  16. return sessionDatas.find(sessionData => sessionData.mode === mode
  17. && (sessionData.status === statusConstants.ON
  18. || sessionData.status === statusConstants.PENDING));
  19. }
  20. /**
  21. * Returns an estimated recording duration based on the size of the video file
  22. * in MB. The estimate is calculated under the assumption that 1 min of recorded
  23. * video needs 10MB of storage on average.
  24. *
  25. * @param {number} size - The size in MB of the recorded video.
  26. * @returns {number} - The estimated duration in minutes.
  27. */
  28. export function getRecordingDurationEstimation(size: ?number) {
  29. return Math.floor((size || 0) / 10);
  30. }
  31. /**
  32. * Searches in the passed in redux state for a recording session that matches
  33. * the passed in recording session ID.
  34. *
  35. * @param {Object} state - The redux state to search in.
  36. * @param {string} id - The ID of the recording session to find.
  37. * @returns {Object|undefined}
  38. */
  39. export function getSessionById(state: Object, id: string) {
  40. return state['features/recording'].sessionDatas.find(
  41. sessionData => sessionData.id === id);
  42. }
  43. /**
  44. * Fetches the recording link from the server.
  45. *
  46. * @param {string} url - The base url.
  47. * @param {string} recordingSessionId - The ID of the recording session to find.
  48. * @param {string} region - The meeting region.
  49. * @param {string} tenant - The meeting tenant.
  50. * @returns {Promise<any>}
  51. */
  52. export async function getRecordingLink(url: string, recordingSessionId: string, region: string, tenant: string) {
  53. const fullUrl = `${url}?recordingSessionId=${recordingSessionId}&region=${region}&tenant=${tenant}`;
  54. const res = await fetch(fullUrl, {
  55. headers: {
  56. 'Content-Type': 'application/json'
  57. }
  58. });
  59. const json = await res.json();
  60. return res.ok ? json.url : Promise.reject(json);
  61. }
  62. /**
  63. * Selector used for determining if recording is saved on dropbox.
  64. *
  65. * @param {Object} state - The redux state to search in.
  66. * @returns {string}
  67. */
  68. export function isSavingRecordingOnDropbox(state: Object) {
  69. return isDropboxEnabled(state)
  70. && state['features/recording'].selectedRecordingService === RECORDING_TYPES.DROPBOX;
  71. }
  72. /**
  73. * Returns the recording session status that is to be shown in a label. E.g. If
  74. * there is a session with the status OFF and one with PENDING, then the PENDING
  75. * one will be shown, because that is likely more important for the user to see.
  76. *
  77. * @param {Object} state - The redux state to search in.
  78. * @param {string} mode - The recording mode to get status for.
  79. * @returns {string|undefined}
  80. */
  81. export function getSessionStatusToShow(state: Object, mode: string): ?string {
  82. const recordingSessions = state['features/recording'].sessionDatas;
  83. let status;
  84. if (Array.isArray(recordingSessions)) {
  85. for (const session of recordingSessions) {
  86. if (session.mode === mode
  87. && (!status
  88. || (RECORDING_STATUS_PRIORITIES.indexOf(session.status)
  89. > RECORDING_STATUS_PRIORITIES.indexOf(status)))) {
  90. status = session.status;
  91. }
  92. }
  93. }
  94. return status;
  95. }
  96. /**
  97. * Returns the resource id.
  98. *
  99. * @param {Object | string} recorder - A participant or it's resource.
  100. * @returns {string|undefined}
  101. */
  102. export function getResourceId(recorder: string | Object) {
  103. if (recorder) {
  104. return typeof recorder === 'string'
  105. ? recorder
  106. : recorder.getId();
  107. }
  108. }