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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 average.
  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. * Fetches the recording link from the server.
  44. *
  45. * @param {string} url - The base url.
  46. * @param {string} recordingSessionId - The ID of the recording session to find.
  47. * @param {string} region - The meeting region.
  48. * @param {string} tenant - The meeting tenant.
  49. * @returns {Promise<any>}
  50. */
  51. export async function getRecordingLink(url: string, recordingSessionId: string, region: string, tenant: string) {
  52. const fullUrl = `${url}?recordingSessionId=${recordingSessionId}&region=${region}&tenant=${tenant}`;
  53. const res = await fetch(fullUrl, {
  54. headers: {
  55. 'Content-Type': 'application/json'
  56. }
  57. });
  58. const json = await res.json();
  59. return res.ok ? json.url : Promise.reject(json);
  60. }
  61. /**
  62. * Returns the recording session status that is to be shown in a label. E.g. If
  63. * there is a session with the status OFF and one with PENDING, then the PENDING
  64. * one will be shown, because that is likely more important for the user to see.
  65. *
  66. * @param {Object} state - The redux state to search in.
  67. * @param {string} mode - The recording mode to get status for.
  68. * @returns {string|undefined}
  69. */
  70. export function getSessionStatusToShow(state: Object, mode: string): ?string {
  71. const recordingSessions = state['features/recording'].sessionDatas;
  72. let status;
  73. if (Array.isArray(recordingSessions)) {
  74. for (const session of recordingSessions) {
  75. if (session.mode === mode
  76. && (!status
  77. || (RECORDING_STATUS_PRIORITIES.indexOf(session.status)
  78. > RECORDING_STATUS_PRIORITIES.indexOf(status)))) {
  79. status = session.status;
  80. }
  81. }
  82. }
  83. return status;
  84. }
  85. /**
  86. * Returns the resource id.
  87. *
  88. * @param {Object | string} recorder - A participant or it's resource.
  89. * @returns {string|undefined}
  90. */
  91. export function getResourceId(recorder: string | Object) {
  92. if (recorder) {
  93. return typeof recorder === 'string'
  94. ? recorder
  95. : recorder.getId();
  96. }
  97. }