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.

reducer.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { ReducerRegistry } from '../base/redux';
  2. import {
  3. CLEAR_RECORDING_SESSIONS,
  4. RECORDING_SESSION_UPDATED,
  5. SET_MEETING_HIGHLIGHT_BUTTON_STATE,
  6. SET_PENDING_RECORDING_NOTIFICATION_UID,
  7. SET_SELECTED_RECORDING_SERVICE,
  8. SET_STREAM_KEY
  9. } from './actionTypes';
  10. const DEFAULT_STATE = {
  11. disableHighlightMeetingMoment: false,
  12. pendingNotificationUids: {},
  13. selectedRecordingService: '',
  14. sessionDatas: []
  15. };
  16. /**
  17. * The name of the Redux store this feature stores its state in.
  18. */
  19. const STORE_NAME = 'features/recording';
  20. /**
  21. * Reduces the Redux actions of the feature features/recording.
  22. */
  23. ReducerRegistry.register(STORE_NAME,
  24. (state = DEFAULT_STATE, action) => {
  25. switch (action.type) {
  26. case CLEAR_RECORDING_SESSIONS:
  27. return {
  28. ...state,
  29. sessionDatas: []
  30. };
  31. case RECORDING_SESSION_UPDATED:
  32. return {
  33. ...state,
  34. sessionDatas:
  35. _updateSessionDatas(state.sessionDatas, action.sessionData)
  36. };
  37. case SET_PENDING_RECORDING_NOTIFICATION_UID: {
  38. const pendingNotificationUids = {
  39. ...state.pendingNotificationUids
  40. };
  41. pendingNotificationUids[action.streamType] = action.uid;
  42. return {
  43. ...state,
  44. pendingNotificationUids
  45. };
  46. }
  47. case SET_SELECTED_RECORDING_SERVICE: {
  48. return {
  49. ...state,
  50. selectedRecordingService: action.selectedRecordingService
  51. };
  52. }
  53. case SET_STREAM_KEY:
  54. return {
  55. ...state,
  56. streamKey: action.streamKey
  57. };
  58. case SET_MEETING_HIGHLIGHT_BUTTON_STATE:
  59. return {
  60. ...state,
  61. disableHighlightMeetingMoment: action.disabled
  62. };
  63. default:
  64. return state;
  65. }
  66. });
  67. /**
  68. * Updates the known information on recording sessions.
  69. *
  70. * @param {Array} sessionDatas - The current sessions in the redux store.
  71. * @param {Object} newSessionData - The updated session data.
  72. * @private
  73. * @returns {Array} The session datas with the updated session data added.
  74. */
  75. function _updateSessionDatas(sessionDatas, newSessionData) {
  76. const hasExistingSessionData = sessionDatas.find(
  77. sessionData => sessionData.id === newSessionData.id);
  78. let newSessionDatas;
  79. if (hasExistingSessionData) {
  80. newSessionDatas = sessionDatas.map(sessionData => {
  81. if (sessionData.id === newSessionData.id) {
  82. return {
  83. ...newSessionData
  84. };
  85. }
  86. // Nothing to update for this session data so pass it back in.
  87. return sessionData;
  88. });
  89. } else {
  90. // If the session data is not present, then there is nothing to update
  91. // and instead it needs to be added to the known session datas.
  92. newSessionDatas = [
  93. ...sessionDatas,
  94. { ...newSessionData }
  95. ];
  96. }
  97. return newSessionDatas;
  98. }