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

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