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

reducer.js 2.8KB

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