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

reducer.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // @flow
  2. import { PARTICIPANT_JOINED, PARTICIPANT_LEFT } from '../base/participants';
  3. import { ReducerRegistry } from '../base/redux';
  4. import {
  5. SET_FILMSTRIP_ENABLED,
  6. SET_FILMSTRIP_VISIBLE,
  7. SET_HORIZONTAL_VIEW_DIMENSIONS,
  8. SET_TILE_VIEW_DIMENSIONS,
  9. SET_VERTICAL_VIEW_DIMENSIONS,
  10. SET_VOLUME
  11. } from './actionTypes';
  12. const DEFAULT_STATE = {
  13. /**
  14. * The indicator which determines whether the {@link Filmstrip} is enabled.
  15. *
  16. * @public
  17. * @type {boolean}
  18. */
  19. enabled: true,
  20. /**
  21. * The horizontal view dimensions.
  22. *
  23. * @public
  24. * @type {Object}
  25. */
  26. horizontalViewDimensions: {},
  27. /**
  28. * The custom audio volume levels per perticipant.
  29. *
  30. * @type {Object}
  31. */
  32. participantsVolume: {},
  33. /**
  34. * The ordered IDs of the remote participants displayed in the filmstrip.
  35. *
  36. * NOTE: Currently the order will match the one from the base/participants array. But this is good initial step for
  37. * reordering the remote participants.
  38. */
  39. remoteParticipants: [],
  40. /**
  41. * The tile view dimensions.
  42. *
  43. * @public
  44. * @type {Object}
  45. */
  46. tileViewDimensions: {},
  47. /**
  48. * The vertical view dimensions.
  49. *
  50. * @public
  51. * @type {Object}
  52. */
  53. verticalViewDimensions: {},
  54. /**
  55. * The indicator which determines whether the {@link Filmstrip} is visible.
  56. *
  57. * @public
  58. * @type {boolean}
  59. */
  60. visible: true
  61. };
  62. ReducerRegistry.register(
  63. 'features/filmstrip',
  64. (state = DEFAULT_STATE, action) => {
  65. switch (action.type) {
  66. case SET_FILMSTRIP_ENABLED:
  67. return {
  68. ...state,
  69. enabled: action.enabled
  70. };
  71. case SET_FILMSTRIP_VISIBLE:
  72. return {
  73. ...state,
  74. visible: action.visible
  75. };
  76. case SET_HORIZONTAL_VIEW_DIMENSIONS:
  77. return {
  78. ...state,
  79. horizontalViewDimensions: action.dimensions
  80. };
  81. case SET_TILE_VIEW_DIMENSIONS:
  82. return {
  83. ...state,
  84. tileViewDimensions: action.dimensions
  85. };
  86. case SET_VERTICAL_VIEW_DIMENSIONS:
  87. return {
  88. ...state,
  89. verticalViewDimensions: action.dimensions
  90. };
  91. case SET_VOLUME:
  92. return {
  93. ...state,
  94. participantsVolume: {
  95. ...state.participantsVolume,
  96. // NOTE: This would fit better in the features/base/participants. But currently we store
  97. // the participants as an array which will make it expensive to search for the volume for
  98. // every participant separately.
  99. [action.participantId]: action.volume
  100. }
  101. };
  102. case PARTICIPANT_JOINED: {
  103. const { id, local } = action.participant;
  104. if (!local) {
  105. state.remoteParticipants = [ ...state.remoteParticipants, id ];
  106. }
  107. return state;
  108. }
  109. case PARTICIPANT_LEFT: {
  110. const { id, local } = action.participant;
  111. if (local) {
  112. return state;
  113. }
  114. state.remoteParticipants = state.remoteParticipants.filter(participantId => participantId !== id);
  115. delete state.participantsVolume[id];
  116. return state;
  117. }
  118. }
  119. return state;
  120. });