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 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // @flow
  2. import Filmstrip from '../../../modules/UI/videolayout/Filmstrip';
  3. import VideoLayout from '../../../modules/UI/videolayout/VideoLayout';
  4. import { StateListenerRegistry, equals } from '../base/redux';
  5. import { setFilmstripVisible } from '../filmstrip/actions';
  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. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  66. // Once the thumbnails are reactified this should be moved there too.
  67. Filmstrip.resizeThumbnailsForVerticalView();
  68. break;
  69. }
  70. });
  71. /**
  72. * Handles on stage participant updates.
  73. */
  74. StateListenerRegistry.register(
  75. /* selector */ state => state['features/large-video'].participantId,
  76. /* listener */ (participantId, store, oldParticipantId) => {
  77. const newThumbnail = VideoLayout.getSmallVideo(participantId);
  78. const oldThumbnail = VideoLayout.getSmallVideo(oldParticipantId);
  79. if (newThumbnail) {
  80. newThumbnail.updateView();
  81. }
  82. if (oldThumbnail) {
  83. oldThumbnail.updateView();
  84. }
  85. }
  86. );
  87. /**
  88. * Listens for changes in the chat state to calculate the dimensions of the tile view grid and the tiles.
  89. */
  90. StateListenerRegistry.register(
  91. /* selector */ state => state['features/chat'].isOpen,
  92. /* listener */ (isChatOpen, store) => {
  93. const state = store.getState();
  94. if (isChatOpen) {
  95. // $FlowFixMe
  96. document.body.classList.add('shift-right');
  97. } else {
  98. // $FlowFixMe
  99. document.body.classList.remove('shift-right');
  100. }
  101. if (shouldDisplayTileView(state)) {
  102. const gridDimensions = getTileViewGridDimensions(state);
  103. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  104. store.dispatch(
  105. setTileViewDimensions(
  106. gridDimensions,
  107. {
  108. clientHeight,
  109. clientWidth
  110. },
  111. store
  112. )
  113. );
  114. }
  115. });
  116. /**
  117. * Listens for changes in the client width to determine whether the overflow menu(s) should be displayed as drawers.
  118. */
  119. StateListenerRegistry.register(
  120. /* selector */ state => state['features/base/responsive-ui'].clientWidth < DISPLAY_DRAWER_THRESHOLD,
  121. /* listener */ (widthBelowThreshold, store) => {
  122. store.dispatch(setOverflowDrawer(widthBelowThreshold));
  123. });
  124. /**
  125. * Gracefully hide/show the filmstrip when going past threshold.
  126. */
  127. StateListenerRegistry.register(
  128. /* selector */ state => state['features/base/responsive-ui'].clientWidth < ASPECT_RATIO_BREAKPOINT,
  129. /* listener */ (widthBelowThreshold, store) => {
  130. store.dispatch(setFilmstripVisible(!widthBelowThreshold));
  131. });
  132. /**
  133. * Symbol mapping used for the tile view responsiveness computation.
  134. */
  135. const responsiveColumnMapping = {
  136. multipleColumns: Symbol('multipleColumns'),
  137. singleColumn: Symbol('singleColumn'),
  138. twoColumns: Symbol('twoColumns'),
  139. twoParticipantsSingleColumn: Symbol('twoParticipantsSingleColumn')
  140. };
  141. /**
  142. * Listens for changes in the screen size to recompute
  143. * the dimensions of the tile view grid and the tiles for responsiveness.
  144. */
  145. StateListenerRegistry.register(
  146. /* selector */ state => {
  147. const { clientWidth } = state['features/base/responsive-ui'];
  148. if (clientWidth < TWO_COLUMN_BREAKPOINT && clientWidth >= ASPECT_RATIO_BREAKPOINT) {
  149. // Forcing the recomputation of tiles when screen switches in or out of
  150. // the (TWO_COLUMN_BREAKPOINT, ASPECT_RATIO_BREAKPOINT] interval.
  151. return responsiveColumnMapping.twoColumns;
  152. } else if (clientWidth < ASPECT_RATIO_BREAKPOINT && clientWidth >= SINGLE_COLUMN_BREAKPOINT) {
  153. // Forcing the recomputation of tiles when screen switches in or out of
  154. // the (ASPECT_RATIO_BREAKPOINT, SINGLE_COLUMN_BREAKPOINT] interval.
  155. return responsiveColumnMapping.twoParticipantsSingleColumn;
  156. } else if (clientWidth < SINGLE_COLUMN_BREAKPOINT) {
  157. // Forcing the recomputation of tiles when screen switches below SINGLE_COLUMN_BREAKPOINT.
  158. return responsiveColumnMapping.singleColumn;
  159. }
  160. // Forcing the recomputation of tiles when screen switches above TWO_COLUMN_BREAKPOINT.
  161. return responsiveColumnMapping.multipleColumns;
  162. },
  163. /* listener */ (_, store) => {
  164. const state = store.getState();
  165. if (shouldDisplayTileView(state)) {
  166. const gridDimensions = getTileViewGridDimensions(state);
  167. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  168. store.dispatch(
  169. setTileViewDimensions(
  170. gridDimensions,
  171. {
  172. clientHeight,
  173. clientWidth
  174. },
  175. store
  176. )
  177. );
  178. }
  179. });