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.8KB

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