Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

reducer.ts 3.7KB

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