Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

reducer.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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_VISIBLE_REMOTE_PARTICIPANTS,
  11. SET_VOLUME
  12. } from './actionTypes';
  13. const DEFAULT_STATE = {
  14. /**
  15. * The indicator which determines whether the {@link Filmstrip} is enabled.
  16. *
  17. * @public
  18. * @type {boolean}
  19. */
  20. enabled: true,
  21. /**
  22. * The horizontal view dimensions.
  23. *
  24. * @public
  25. * @type {Object}
  26. */
  27. horizontalViewDimensions: {},
  28. /**
  29. * The custom audio volume levels per perticipant.
  30. *
  31. * @type {Object}
  32. */
  33. participantsVolume: {},
  34. /**
  35. * The ordered IDs of the remote participants displayed in the filmstrip.
  36. *
  37. * NOTE: Currently the order will match the one from the base/participants array. But this is good initial step for
  38. * reordering the remote participants.
  39. */
  40. remoteParticipants: [],
  41. /**
  42. * The tile view dimensions.
  43. *
  44. * @public
  45. * @type {Object}
  46. */
  47. tileViewDimensions: {},
  48. /**
  49. * The vertical view dimensions.
  50. *
  51. * @public
  52. * @type {Object}
  53. */
  54. verticalViewDimensions: {},
  55. /**
  56. * The indicator which determines whether the {@link Filmstrip} is visible.
  57. *
  58. * @public
  59. * @type {boolean}
  60. */
  61. visible: true,
  62. /**
  63. * The end index in the remote participants array that is visible in the filmstrip.
  64. *
  65. * @public
  66. * @type {number}
  67. */
  68. visibleParticipantsEndIndex: 0,
  69. /**
  70. * The visible participants in the filmstrip.
  71. *
  72. * @public
  73. * @type {Array<string>}
  74. */
  75. visibleParticipants: [],
  76. /**
  77. * The start index in the remote participants array that is visible in the filmstrip.
  78. *
  79. * @public
  80. * @type {number}
  81. */
  82. visibleParticipantsStartIndex: 0
  83. };
  84. ReducerRegistry.register(
  85. 'features/filmstrip',
  86. (state = DEFAULT_STATE, action) => {
  87. switch (action.type) {
  88. case SET_FILMSTRIP_ENABLED:
  89. return {
  90. ...state,
  91. enabled: action.enabled
  92. };
  93. case SET_FILMSTRIP_VISIBLE:
  94. return {
  95. ...state,
  96. visible: action.visible
  97. };
  98. case SET_HORIZONTAL_VIEW_DIMENSIONS:
  99. return {
  100. ...state,
  101. horizontalViewDimensions: action.dimensions
  102. };
  103. case SET_TILE_VIEW_DIMENSIONS:
  104. return {
  105. ...state,
  106. tileViewDimensions: action.dimensions
  107. };
  108. case SET_VERTICAL_VIEW_DIMENSIONS:
  109. return {
  110. ...state,
  111. verticalViewDimensions: action.dimensions
  112. };
  113. case SET_VOLUME:
  114. return {
  115. ...state,
  116. participantsVolume: {
  117. ...state.participantsVolume,
  118. // NOTE: This would fit better in the features/base/participants. But currently we store
  119. // the participants as an array which will make it expensive to search for the volume for
  120. // every participant separately.
  121. [action.participantId]: action.volume
  122. }
  123. };
  124. case SET_VISIBLE_REMOTE_PARTICIPANTS:
  125. return {
  126. ...state,
  127. visibleParticipantsStartIndex: action.startIndex,
  128. visibleParticipantsEndIndex: action.endIndex,
  129. visibleParticipants: state.remoteParticipants.slice(action.startIndex, action.endIndex + 1)
  130. };
  131. case PARTICIPANT_JOINED: {
  132. const { id, local } = action.participant;
  133. if (!local) {
  134. state.remoteParticipants = [ ...state.remoteParticipants, id ];
  135. const { visibleParticipantsStartIndex: startIndex, visibleParticipantsEndIndex: endIndex } = state;
  136. if (state.remoteParticipants.length - 1 <= endIndex) {
  137. state.visibleParticipants = state.remoteParticipants.slice(startIndex, endIndex + 1);
  138. }
  139. }
  140. return state;
  141. }
  142. case PARTICIPANT_LEFT: {
  143. const { id, local } = action.participant;
  144. if (local) {
  145. return state;
  146. }
  147. let removedParticipantIndex = 0;
  148. state.remoteParticipants = state.remoteParticipants.filter((participantId, index) => {
  149. if (participantId === id) {
  150. removedParticipantIndex = index;
  151. return false;
  152. }
  153. return true;
  154. });
  155. const { visibleParticipantsStartIndex: startIndex, visibleParticipantsEndIndex: endIndex } = state;
  156. if (removedParticipantIndex >= startIndex && removedParticipantIndex <= endIndex) {
  157. state.visibleParticipants = state.remoteParticipants.slice(startIndex, endIndex + 1);
  158. }
  159. delete state.participantsVolume[id];
  160. return state;
  161. }
  162. }
  163. return state;
  164. });