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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // @flow
  2. import { StateListenerRegistry, equals } from '../base/redux';
  3. import { clientResized } from '../base/responsive-ui';
  4. import { setFilmstripVisible } from '../filmstrip/actions';
  5. import { getParticipantsPaneOpen } from '../participants-pane/functions';
  6. import { setOverflowDrawer } from '../toolbox/actions.web';
  7. import { getCurrentLayout, getTileViewGridDimensions, shouldDisplayTileView, LAYOUTS } from '../video-layout';
  8. import { setHorizontalViewDimensions, setTileViewDimensions } from './actions.web';
  9. import {
  10. ASPECT_RATIO_BREAKPOINT,
  11. DISPLAY_DRAWER_THRESHOLD,
  12. SINGLE_COLUMN_BREAKPOINT,
  13. TWO_COLUMN_BREAKPOINT
  14. } from './constants';
  15. /**
  16. * Listens for changes in the number of participants to calculate the dimensions of the tile view grid and the tiles.
  17. */
  18. StateListenerRegistry.register(
  19. /* selector */ state => state['features/base/participants'].length,
  20. /* listener */ (numberOfParticipants, store) => {
  21. const state = store.getState();
  22. if (shouldDisplayTileView(state)) {
  23. const gridDimensions = getTileViewGridDimensions(state);
  24. const oldGridDimensions = state['features/filmstrip'].tileViewDimensions.gridDimensions;
  25. if (!equals(gridDimensions, oldGridDimensions)) {
  26. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  27. store.dispatch(
  28. setTileViewDimensions(
  29. gridDimensions,
  30. {
  31. clientHeight,
  32. clientWidth
  33. },
  34. store
  35. )
  36. );
  37. }
  38. }
  39. });
  40. /**
  41. * Listens for changes in the selected layout to calculate the dimensions of the tile view grid and horizontal view.
  42. */
  43. StateListenerRegistry.register(
  44. /* selector */ state => getCurrentLayout(state),
  45. /* listener */ (layout, store) => {
  46. const state = store.getState();
  47. switch (layout) {
  48. case LAYOUTS.TILE_VIEW: {
  49. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  50. store.dispatch(
  51. setTileViewDimensions(
  52. getTileViewGridDimensions(state),
  53. {
  54. clientHeight,
  55. clientWidth
  56. },
  57. store
  58. )
  59. );
  60. break;
  61. }
  62. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW:
  63. store.dispatch(setHorizontalViewDimensions(state['features/base/responsive-ui'].clientHeight));
  64. break;
  65. }
  66. });
  67. /**
  68. * Listens for changes in the chat state to recompute available width.
  69. */
  70. StateListenerRegistry.register(
  71. /* selector */ state => state['features/chat'].isOpen,
  72. /* listener */ (isChatOpen, store) => {
  73. const { innerWidth, innerHeight } = window;
  74. if (isChatOpen) {
  75. // $FlowFixMe
  76. document.body.classList.add('shift-right');
  77. } else {
  78. // $FlowFixMe
  79. document.body.classList.remove('shift-right');
  80. }
  81. store.dispatch(clientResized(innerWidth, innerHeight));
  82. });
  83. /**
  84. * Listens for changes in the participant pane state to calculate the
  85. * dimensions of the tile view grid and the tiles.
  86. */
  87. StateListenerRegistry.register(
  88. /* selector */ getParticipantsPaneOpen,
  89. /* listener */ (isOpen, store) => {
  90. const { innerWidth, innerHeight } = window;
  91. store.dispatch(clientResized(innerWidth, innerHeight));
  92. });
  93. /**
  94. * Listens for changes in the client width to determine whether the overflow menu(s) should be displayed as drawers.
  95. */
  96. StateListenerRegistry.register(
  97. /* selector */ state => state['features/base/responsive-ui'].clientWidth < DISPLAY_DRAWER_THRESHOLD,
  98. /* listener */ (widthBelowThreshold, store) => {
  99. store.dispatch(setOverflowDrawer(widthBelowThreshold));
  100. });
  101. /**
  102. * Gracefully hide/show the filmstrip when going past threshold.
  103. */
  104. StateListenerRegistry.register(
  105. /* selector */ state => state['features/base/responsive-ui'].clientWidth < ASPECT_RATIO_BREAKPOINT,
  106. /* listener */ (widthBelowThreshold, store) => {
  107. store.dispatch(setFilmstripVisible(!widthBelowThreshold));
  108. });
  109. /**
  110. * Symbol mapping used for the tile view responsiveness computation.
  111. */
  112. const responsiveColumnMapping = {
  113. multipleColumns: Symbol('multipleColumns'),
  114. singleColumn: Symbol('singleColumn'),
  115. twoColumns: Symbol('twoColumns'),
  116. twoParticipantsSingleColumn: Symbol('twoParticipantsSingleColumn')
  117. };
  118. /**
  119. * Listens for changes in the screen size to recompute
  120. * the dimensions of the tile view grid and the tiles for responsiveness.
  121. */
  122. StateListenerRegistry.register(
  123. /* selector */ state => {
  124. const { clientWidth } = state['features/base/responsive-ui'];
  125. if (clientWidth < TWO_COLUMN_BREAKPOINT && clientWidth >= ASPECT_RATIO_BREAKPOINT) {
  126. // Forcing the recomputation of tiles when screen switches in or out of
  127. // the (TWO_COLUMN_BREAKPOINT, ASPECT_RATIO_BREAKPOINT] interval.
  128. return responsiveColumnMapping.twoColumns;
  129. } else if (clientWidth < ASPECT_RATIO_BREAKPOINT && clientWidth >= SINGLE_COLUMN_BREAKPOINT) {
  130. // Forcing the recomputation of tiles when screen switches in or out of
  131. // the (ASPECT_RATIO_BREAKPOINT, SINGLE_COLUMN_BREAKPOINT] interval.
  132. return responsiveColumnMapping.twoParticipantsSingleColumn;
  133. } else if (clientWidth < SINGLE_COLUMN_BREAKPOINT) {
  134. // Forcing the recomputation of tiles when screen switches below SINGLE_COLUMN_BREAKPOINT.
  135. return responsiveColumnMapping.singleColumn;
  136. }
  137. // Forcing the recomputation of tiles when screen switches above TWO_COLUMN_BREAKPOINT.
  138. return responsiveColumnMapping.multipleColumns;
  139. },
  140. /* listener */ (_, store) => {
  141. const state = store.getState();
  142. if (shouldDisplayTileView(state)) {
  143. const gridDimensions = getTileViewGridDimensions(state);
  144. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  145. store.dispatch(
  146. setTileViewDimensions(
  147. gridDimensions,
  148. {
  149. clientHeight,
  150. clientWidth
  151. },
  152. store
  153. )
  154. );
  155. }
  156. });