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.

subscriber.web.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // @flow
  2. import { isMobileBrowser } from '../base/environment/utils';
  3. import { getParticipantCountWithFake, pinParticipant } from '../base/participants';
  4. import { StateListenerRegistry } from '../base/redux';
  5. import { clientResized } from '../base/responsive-ui';
  6. import { shouldHideSelfView } from '../base/settings';
  7. import { setFilmstripVisible } from '../filmstrip/actions';
  8. import { selectParticipantInLargeVideo } from '../large-video/actions.any';
  9. import { getParticipantsPaneOpen } from '../participants-pane/functions';
  10. import { setOverflowDrawer } from '../toolbox/actions.web';
  11. import { getCurrentLayout, shouldDisplayTileView, LAYOUTS } from '../video-layout';
  12. import {
  13. clearStageParticipants,
  14. setHorizontalViewDimensions,
  15. setStageFilmstripViewDimensions,
  16. setTileViewDimensions,
  17. setVerticalViewDimensions
  18. } from './actions';
  19. import {
  20. ASPECT_RATIO_BREAKPOINT,
  21. DISPLAY_DRAWER_THRESHOLD
  22. } from './constants';
  23. import {
  24. isFilmstripResizable
  25. } from './functions';
  26. import './subscriber.any';
  27. /**
  28. * Listens for changes in the number of participants to calculate the dimensions of the tile view grid and the tiles.
  29. */
  30. StateListenerRegistry.register(
  31. /* selector */ state => {
  32. return {
  33. numberOfParticipants: getParticipantCountWithFake(state),
  34. disableSelfView: shouldHideSelfView(state),
  35. localScreenShare: state['features/base/participants'].localScreenShare
  36. };
  37. },
  38. /* listener */ (currentState, store) => {
  39. const state = store.getState();
  40. const resizableFilmstrip = isFilmstripResizable(state);
  41. if (shouldDisplayTileView(state)) {
  42. store.dispatch(setTileViewDimensions());
  43. }
  44. if (resizableFilmstrip) {
  45. store.dispatch(setVerticalViewDimensions());
  46. }
  47. }, {
  48. deepEquals: true
  49. });
  50. /**
  51. * Listens for changes in the selected layout to calculate the dimensions of the tile view grid and horizontal view.
  52. */
  53. StateListenerRegistry.register(
  54. /* selector */ state => {
  55. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  56. return {
  57. layout: getCurrentLayout(state),
  58. height: clientHeight,
  59. width: clientWidth
  60. };
  61. },
  62. /* listener */ ({ layout }, store) => {
  63. switch (layout) {
  64. case LAYOUTS.TILE_VIEW:
  65. store.dispatch(setTileViewDimensions());
  66. break;
  67. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW:
  68. store.dispatch(setHorizontalViewDimensions());
  69. break;
  70. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  71. store.dispatch(setVerticalViewDimensions());
  72. if (store.getState()['features/filmstrip'].activeParticipants.length > 1) {
  73. store.dispatch(clearStageParticipants());
  74. }
  75. break;
  76. case LAYOUTS.STAGE_FILMSTRIP_VIEW:
  77. store.dispatch(pinParticipant(null));
  78. break;
  79. }
  80. }, {
  81. deepEquals: true
  82. });
  83. /**
  84. * Listens for changes in the chat state to recompute available width.
  85. */
  86. StateListenerRegistry.register(
  87. /* selector */ state => state['features/chat'].isOpen,
  88. /* listener */ (isChatOpen, store) => {
  89. const { innerWidth, innerHeight } = window;
  90. if (isChatOpen) {
  91. // $FlowFixMe
  92. document.body.classList.add('shift-right');
  93. } else {
  94. // $FlowFixMe
  95. document.body.classList.remove('shift-right');
  96. }
  97. store.dispatch(clientResized(innerWidth, innerHeight));
  98. });
  99. /**
  100. * Listens for changes in the participant pane state to calculate the
  101. * dimensions of the tile view grid and the tiles.
  102. */
  103. StateListenerRegistry.register(
  104. /* selector */ getParticipantsPaneOpen,
  105. /* listener */ (isOpen, store) => {
  106. const { innerWidth, innerHeight } = window;
  107. store.dispatch(clientResized(innerWidth, innerHeight));
  108. });
  109. /**
  110. * Listens for changes in the client width to determine whether the overflow menu(s) should be displayed as drawers.
  111. */
  112. StateListenerRegistry.register(
  113. /* selector */ state => state['features/base/responsive-ui'].clientWidth < DISPLAY_DRAWER_THRESHOLD,
  114. /* listener */ (widthBelowThreshold, store) => {
  115. if (isMobileBrowser()) {
  116. store.dispatch(setOverflowDrawer(widthBelowThreshold));
  117. }
  118. });
  119. /**
  120. * Gracefully hide/show the filmstrip when going past threshold.
  121. */
  122. StateListenerRegistry.register(
  123. /* selector */ state => state['features/base/responsive-ui'].clientWidth < ASPECT_RATIO_BREAKPOINT,
  124. /* listener */ (widthBelowThreshold, store) => {
  125. const state = store.getState();
  126. const { disableFilmstripAutohiding } = state['features/base/config'];
  127. if (!disableFilmstripAutohiding) {
  128. store.dispatch(setFilmstripVisible(!widthBelowThreshold));
  129. }
  130. });
  131. /**
  132. * Listens for changes in the filmstrip width to determine the size of the tiles.
  133. */
  134. StateListenerRegistry.register(
  135. /* selector */ state => state['features/filmstrip'].width?.current,
  136. /* listener */(_, store) => {
  137. store.dispatch(setVerticalViewDimensions());
  138. });
  139. /**
  140. * Listens for changes in the filmstrip config to determine the size of the tiles.
  141. */
  142. StateListenerRegistry.register(
  143. /* selector */ state => state['features/base/config'].filmstrip?.disableResizable,
  144. /* listener */(_, store) => {
  145. store.dispatch(setVerticalViewDimensions());
  146. });
  147. /**
  148. * Listens for changes to determine the size of the stage filmstrip tiles.
  149. */
  150. StateListenerRegistry.register(
  151. /* selector */ state => {
  152. return {
  153. remoteScreenShares: state['features/video-layout'].remoteScreenShares.length,
  154. length: state['features/filmstrip'].activeParticipants.length,
  155. width: state['features/filmstrip'].width?.current,
  156. visible: state['features/filmstrip'].visible,
  157. clientWidth: state['features/base/responsive-ui'].clientWidth,
  158. tileView: state['features/video-layout'].tileViewEnabled
  159. };
  160. },
  161. /* listener */(_, store) => {
  162. if (getCurrentLayout(store.getState()) === LAYOUTS.STAGE_FILMSTRIP_VIEW) {
  163. store.dispatch(setStageFilmstripViewDimensions());
  164. }
  165. }, {
  166. deepEquals: true
  167. });
  168. /**
  169. * Listens for changes in the active participants count determine the stage participant (when
  170. * there's just one).
  171. */
  172. StateListenerRegistry.register(
  173. /* selector */ state => state['features/filmstrip'].activeParticipants.length,
  174. /* listener */(length, store) => {
  175. if (length <= 1) {
  176. store.dispatch(selectParticipantInLargeVideo());
  177. }
  178. });