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.ts 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  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_START_RECORDING_NOTIFICATION_SHOWN,
  9. SET_STREAM_KEY
  10. } from './actionTypes';
  11. const DEFAULT_STATE = {
  12. disableHighlightMeetingMoment: false,
  13. pendingNotificationUids: {},
  14. selectedRecordingService: '',
  15. sessionDatas: []
  16. };
  17. export interface ISessionData {
  18. error?: Error;
  19. id?: string;
  20. initiator?: { getId: Function; };
  21. liveStreamViewURL?: string;
  22. mode?: string;
  23. status?: string;
  24. terminator?: { getId: Function; };
  25. timestamp?: number;
  26. }
  27. export interface IRecordingState {
  28. disableHighlightMeetingMoment: boolean;
  29. pendingNotificationUids: {
  30. [key: string]: string | undefined;
  31. };
  32. selectedRecordingService: string;
  33. sessionDatas: Array<ISessionData>;
  34. streamKey?: string;
  35. wasStartRecordingSuggested?: boolean;
  36. }
  37. /**
  38. * The name of the Redux store this feature stores its state in.
  39. */
  40. const STORE_NAME = 'features/recording';
  41. /**
  42. * Reduces the Redux actions of the feature features/recording.
  43. */
  44. ReducerRegistry.register<IRecordingState>(STORE_NAME,
  45. (state = DEFAULT_STATE, action): IRecordingState => {
  46. switch (action.type) {
  47. case CLEAR_RECORDING_SESSIONS:
  48. return {
  49. ...state,
  50. sessionDatas: []
  51. };
  52. case RECORDING_SESSION_UPDATED:
  53. return {
  54. ...state,
  55. sessionDatas:
  56. _updateSessionDatas(state.sessionDatas, action.sessionData)
  57. };
  58. case SET_PENDING_RECORDING_NOTIFICATION_UID: {
  59. const pendingNotificationUids = {
  60. ...state.pendingNotificationUids
  61. };
  62. pendingNotificationUids[action.streamType] = action.uid;
  63. return {
  64. ...state,
  65. pendingNotificationUids
  66. };
  67. }
  68. case SET_SELECTED_RECORDING_SERVICE: {
  69. return {
  70. ...state,
  71. selectedRecordingService: action.selectedRecordingService
  72. };
  73. }
  74. case SET_STREAM_KEY:
  75. return {
  76. ...state,
  77. streamKey: action.streamKey
  78. };
  79. case SET_MEETING_HIGHLIGHT_BUTTON_STATE:
  80. return {
  81. ...state,
  82. disableHighlightMeetingMoment: action.disabled
  83. };
  84. case SET_START_RECORDING_NOTIFICATION_SHOWN:
  85. return {
  86. ...state,
  87. wasStartRecordingSuggested: true
  88. };
  89. default:
  90. return state;
  91. }
  92. });
  93. /**
  94. * Updates the known information on recording sessions.
  95. *
  96. * @param {Array} sessionDatas - The current sessions in the redux store.
  97. * @param {Object} newSessionData - The updated session data.
  98. * @private
  99. * @returns {Array} The session datas with the updated session data added.
  100. */
  101. function _updateSessionDatas(sessionDatas: ISessionData[], newSessionData: ISessionData) {
  102. const hasExistingSessionData = sessionDatas.find(
  103. sessionData => sessionData.id === newSessionData.id);
  104. let newSessionDatas;
  105. if (hasExistingSessionData) {
  106. newSessionDatas = sessionDatas.map(sessionData => {
  107. if (sessionData.id === newSessionData.id) {
  108. return {
  109. ...newSessionData
  110. };
  111. }
  112. // Nothing to update for this session data so pass it back in.
  113. return sessionData;
  114. });
  115. } else {
  116. // If the session data is not present, then there is nothing to update
  117. // and instead it needs to be added to the known session datas.
  118. newSessionDatas = [
  119. ...sessionDatas,
  120. { ...newSessionData }
  121. ];
  122. }
  123. return newSessionDatas;
  124. }