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

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