您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

reducer.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. // console.log("MRR~q2")
  88. console.trace("MRR~q2")
  89. switch (action.type) {
  90. case SET_FILMSTRIP_ENABLED:
  91. return {
  92. ...state,
  93. enabled: action.enabled
  94. };
  95. case SET_FILMSTRIP_VISIBLE:
  96. return {
  97. ...state,
  98. visible: action.visible
  99. };
  100. case SET_HORIZONTAL_VIEW_DIMENSIONS:
  101. return {
  102. ...state,
  103. horizontalViewDimensions: action.dimensions
  104. };
  105. case SET_TILE_VIEW_DIMENSIONS:
  106. return {
  107. ...state,
  108. tileViewDimensions: action.dimensions
  109. };
  110. case SET_VERTICAL_VIEW_DIMENSIONS:
  111. return {
  112. ...state,
  113. verticalViewDimensions: action.dimensions
  114. };
  115. case SET_VOLUME:
  116. return {
  117. ...state,
  118. participantsVolume: {
  119. ...state.participantsVolume,
  120. // NOTE: This would fit better in the features/base/participants. But currently we store
  121. // the participants as an array which will make it expensive to search for the volume for
  122. // every participant separately.
  123. [action.participantId]: action.volume
  124. }
  125. };
  126. case SET_VISIBLE_REMOTE_PARTICIPANTS:
  127. return {
  128. ...state,
  129. visibleParticipantsStartIndex: action.startIndex,
  130. visibleParticipantsEndIndex: action.endIndex,
  131. visibleParticipants: state.remoteParticipants.slice(action.startIndex, action.endIndex + 1)
  132. };
  133. case PARTICIPANT_JOINED: {
  134. const { id, local } = action.participant;
  135. if (!local) {
  136. state.remoteParticipants = [ ...state.remoteParticipants, id ];
  137. const { visibleParticipantsStartIndex: startIndex, visibleParticipantsEndIndex: endIndex } = state;
  138. if (state.remoteParticipants.length - 1 <= endIndex) {
  139. state.visibleParticipants = state.remoteParticipants.slice(startIndex, endIndex + 1);
  140. }
  141. }
  142. return state;
  143. }
  144. case PARTICIPANT_LEFT: {
  145. const { id, local } = action.participant;
  146. if (local) {
  147. return state;
  148. }
  149. let removedParticipantIndex = 0;
  150. state.remoteParticipants = state.remoteParticipants.filter((participantId, index) => {
  151. if (participantId === id) {
  152. removedParticipantIndex = index;
  153. return false;
  154. }
  155. return true;
  156. });
  157. const { visibleParticipantsStartIndex: startIndex, visibleParticipantsEndIndex: endIndex } = state;
  158. if (removedParticipantIndex >= startIndex && removedParticipantIndex <= endIndex) {
  159. state.visibleParticipants = state.remoteParticipants.slice(startIndex, endIndex + 1);
  160. }
  161. delete state.participantsVolume[id];
  162. return state;
  163. }
  164. }
  165. return state;
  166. });