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

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