Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

subscriber.web.js 6.3KB

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