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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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, setVerticalViewDimensions } 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. store.dispatch(setTileViewDimensions(gridDimensions));
  27. }
  28. }
  29. });
  30. /**
  31. * Listens for changes in the selected layout to calculate the dimensions of the tile view grid and horizontal view.
  32. */
  33. StateListenerRegistry.register(
  34. /* selector */ state => getCurrentLayout(state),
  35. /* listener */ (layout, store) => {
  36. const state = store.getState();
  37. switch (layout) {
  38. case LAYOUTS.TILE_VIEW:
  39. store.dispatch(setTileViewDimensions(getTileViewGridDimensions(state)));
  40. break;
  41. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW:
  42. store.dispatch(setHorizontalViewDimensions());
  43. break;
  44. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  45. store.dispatch(setVerticalViewDimensions());
  46. break;
  47. }
  48. });
  49. /**
  50. * Listens for changes in the chat state to recompute available width.
  51. */
  52. StateListenerRegistry.register(
  53. /* selector */ state => state['features/chat'].isOpen,
  54. /* listener */ (isChatOpen, store) => {
  55. const { innerWidth, innerHeight } = window;
  56. if (isChatOpen) {
  57. // $FlowFixMe
  58. document.body.classList.add('shift-right');
  59. } else {
  60. // $FlowFixMe
  61. document.body.classList.remove('shift-right');
  62. }
  63. store.dispatch(clientResized(innerWidth, innerHeight));
  64. });
  65. /**
  66. * Listens for changes in the participant pane state to calculate the
  67. * dimensions of the tile view grid and the tiles.
  68. */
  69. StateListenerRegistry.register(
  70. /* selector */ getParticipantsPaneOpen,
  71. /* listener */ (isOpen, store) => {
  72. const { innerWidth, innerHeight } = window;
  73. store.dispatch(clientResized(innerWidth, innerHeight));
  74. });
  75. /**
  76. * Listens for changes in the client width to determine whether the overflow menu(s) should be displayed as drawers.
  77. */
  78. StateListenerRegistry.register(
  79. /* selector */ state => state['features/base/responsive-ui'].clientWidth < DISPLAY_DRAWER_THRESHOLD,
  80. /* listener */ (widthBelowThreshold, store) => {
  81. store.dispatch(setOverflowDrawer(widthBelowThreshold));
  82. });
  83. /**
  84. * Gracefully hide/show the filmstrip when going past threshold.
  85. */
  86. StateListenerRegistry.register(
  87. /* selector */ state => state['features/base/responsive-ui'].clientWidth < ASPECT_RATIO_BREAKPOINT,
  88. /* listener */ (widthBelowThreshold, store) => {
  89. const state = store.getState();
  90. const { disableFilmstripAutohiding } = state['features/base/config'];
  91. if (!disableFilmstripAutohiding) {
  92. store.dispatch(setFilmstripVisible(!widthBelowThreshold));
  93. }
  94. });
  95. /**
  96. * Symbol mapping used for the tile view responsiveness computation.
  97. */
  98. const responsiveColumnMapping = {
  99. multipleColumns: Symbol('multipleColumns'),
  100. singleColumn: Symbol('singleColumn'),
  101. twoColumns: Symbol('twoColumns'),
  102. twoParticipantsSingleColumn: Symbol('twoParticipantsSingleColumn')
  103. };
  104. /**
  105. * Listens for changes in the screen size to recompute
  106. * the dimensions of the tile view grid and the tiles for responsiveness.
  107. */
  108. StateListenerRegistry.register(
  109. /* selector */ state => {
  110. const { clientWidth } = state['features/base/responsive-ui'];
  111. if (clientWidth < TWO_COLUMN_BREAKPOINT && clientWidth >= ASPECT_RATIO_BREAKPOINT) {
  112. // Forcing the recomputation of tiles when screen switches in or out of
  113. // the (TWO_COLUMN_BREAKPOINT, ASPECT_RATIO_BREAKPOINT] interval.
  114. return responsiveColumnMapping.twoColumns;
  115. } else if (clientWidth < ASPECT_RATIO_BREAKPOINT && clientWidth >= SINGLE_COLUMN_BREAKPOINT) {
  116. // Forcing the recomputation of tiles when screen switches in or out of
  117. // the (ASPECT_RATIO_BREAKPOINT, SINGLE_COLUMN_BREAKPOINT] interval.
  118. return responsiveColumnMapping.twoParticipantsSingleColumn;
  119. } else if (clientWidth < SINGLE_COLUMN_BREAKPOINT) {
  120. // Forcing the recomputation of tiles when screen switches below SINGLE_COLUMN_BREAKPOINT.
  121. return responsiveColumnMapping.singleColumn;
  122. }
  123. // Forcing the recomputation of tiles when screen switches above TWO_COLUMN_BREAKPOINT.
  124. return responsiveColumnMapping.multipleColumns;
  125. },
  126. /* listener */ (_, store) => {
  127. const state = store.getState();
  128. if (shouldDisplayTileView(state)) {
  129. const gridDimensions = getTileViewGridDimensions(state);
  130. store.dispatch(setTileViewDimensions(gridDimensions));
  131. }
  132. });