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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  2. import {
  3. SET_INITIALIZED,
  4. SET_INITIAL_PERMANENT_PROPERTIES,
  5. UPDATE_LOCAL_TRACKS_DURATION
  6. } from './actionTypes';
  7. /**
  8. * Initial state.
  9. */
  10. const DEFAULT_STATE = {
  11. isInitialized: false,
  12. initialPermanentProperties: {},
  13. localTracksDuration: {
  14. audio: {
  15. startedTime: -1,
  16. value: 0
  17. },
  18. video: {
  19. camera: {
  20. startedTime: -1,
  21. value: 0
  22. },
  23. desktop: {
  24. startedTime: -1,
  25. value: 0
  26. }
  27. },
  28. conference: {
  29. startedTime: -1,
  30. value: 0
  31. }
  32. }
  33. };
  34. interface IValue {
  35. startedTime: number;
  36. value: number;
  37. }
  38. export interface IAnalyticsState {
  39. initialPermanentProperties: Object;
  40. isInitialized: boolean;
  41. localTracksDuration: {
  42. audio: IValue;
  43. conference: IValue;
  44. video: {
  45. camera: IValue;
  46. desktop: IValue;
  47. };
  48. };
  49. }
  50. /**
  51. * Listen for actions which changes the state of the analytics feature.
  52. *
  53. * @param {Object} state - The Redux state of the feature features/analytics.
  54. * @param {Object} action - Action object.
  55. * @param {string} action.type - Type of action.
  56. * @returns {Object}
  57. */
  58. ReducerRegistry.register<IAnalyticsState>('features/analytics',
  59. (state = DEFAULT_STATE, action): IAnalyticsState => {
  60. switch (action.type) {
  61. case SET_INITIALIZED:
  62. return {
  63. ...state,
  64. initialPermanentProperties: action.value ? state.initialPermanentProperties : {},
  65. isInitialized: action.value
  66. };
  67. case SET_INITIAL_PERMANENT_PROPERTIES:
  68. return {
  69. ...state,
  70. initialPermanentProperties: {
  71. ...state.initialPermanentProperties,
  72. ...action.properties
  73. }
  74. };
  75. case UPDATE_LOCAL_TRACKS_DURATION:
  76. return {
  77. ...state,
  78. localTracksDuration: action.localTracksDuration
  79. };
  80. default:
  81. return state;
  82. }
  83. });