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.

functions.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // @flow
  2. import { getFeatureFlag, TILE_VIEW_ENABLED } from '../base/flags';
  3. import { getPinnedParticipant, getParticipantCount } from '../base/participants';
  4. import { CHAT_SIZE } from '../chat/constants';
  5. import {
  6. ASPECT_RATIO_BREAKPOINT,
  7. DEFAULT_MAX_COLUMNS,
  8. ABSOLUTE_MAX_COLUMNS,
  9. SINGLE_COLUMN_BREAKPOINT,
  10. TWO_COLUMN_BREAKPOINT
  11. } from '../filmstrip/constants';
  12. import { isVideoPlaying } from '../shared-video/functions';
  13. import { LAYOUTS } from './constants';
  14. declare var interfaceConfig: Object;
  15. /**
  16. * Returns the {@code LAYOUTS} constant associated with the layout
  17. * the application should currently be in.
  18. *
  19. * @param {Object} state - The redux state.
  20. * @returns {string}
  21. */
  22. export function getCurrentLayout(state: Object) {
  23. if (shouldDisplayTileView(state)) {
  24. return LAYOUTS.TILE_VIEW;
  25. } else if (interfaceConfig.VERTICAL_FILMSTRIP) {
  26. return LAYOUTS.VERTICAL_FILMSTRIP_VIEW;
  27. }
  28. return LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW;
  29. }
  30. /**
  31. * Returns how many columns should be displayed in tile view. The number
  32. * returned will be between 1 and 7, inclusive.
  33. *
  34. * @param {Object} state - The redux store state.
  35. * @returns {number}
  36. */
  37. export function getMaxColumnCount(state: Object) {
  38. const configuredMax = interfaceConfig.TILE_VIEW_MAX_COLUMNS || DEFAULT_MAX_COLUMNS;
  39. const { disableResponsiveTiles } = state['features/base/config'];
  40. if (!disableResponsiveTiles) {
  41. const { clientWidth } = state['features/base/responsive-ui'];
  42. let availableWidth = clientWidth;
  43. const participantCount = getParticipantCount(state);
  44. const { isOpen } = state['features/chat'];
  45. if (isOpen) {
  46. availableWidth -= CHAT_SIZE;
  47. }
  48. // If there are just two participants in a conference, enforce single-column view for mobile size.
  49. if (participantCount === 2 && availableWidth < ASPECT_RATIO_BREAKPOINT) {
  50. return Math.min(1, Math.max(configuredMax, 1));
  51. }
  52. // Enforce single column view at very small screen widths.
  53. if (availableWidth < SINGLE_COLUMN_BREAKPOINT) {
  54. return Math.min(1, Math.max(configuredMax, 1));
  55. }
  56. // Enforce two column view below breakpoint.
  57. if (availableWidth < TWO_COLUMN_BREAKPOINT) {
  58. return Math.min(2, Math.max(configuredMax, 1));
  59. }
  60. }
  61. return Math.min(Math.max(configuredMax, 1), ABSOLUTE_MAX_COLUMNS);
  62. }
  63. /**
  64. * Returns the cell count dimensions for tile view. Tile view tries to uphold
  65. * equal count of tiles for height and width, until maxColumn is reached in
  66. * which rows will be added but no more columns.
  67. *
  68. * @param {Object} state - The redux store state.
  69. * @param {number} maxColumns - The maximum number of columns that can be
  70. * displayed.
  71. * @returns {Object} An object is return with the desired number of columns,
  72. * rows, and visible rows (the rest should overflow) for the tile view layout.
  73. */
  74. export function getTileViewGridDimensions(state: Object) {
  75. const maxColumns = getMaxColumnCount(state);
  76. // When in tile view mode, we must discount ourselves (the local participant) because our
  77. // tile is not visible.
  78. const { iAmRecorder } = state['features/base/config'];
  79. const numberOfParticipants = state['features/base/participants'].length - (iAmRecorder ? 1 : 0);
  80. const columnsToMaintainASquare = Math.ceil(Math.sqrt(numberOfParticipants));
  81. const columns = Math.min(columnsToMaintainASquare, maxColumns);
  82. const rows = Math.ceil(numberOfParticipants / columns);
  83. const visibleRows = Math.min(maxColumns, rows);
  84. return {
  85. columns,
  86. visibleRows
  87. };
  88. }
  89. /**
  90. * Selector for determining if the UI layout should be in tile view. Tile view
  91. * is determined by more than just having the tile view setting enabled, as
  92. * one-on-one calls should not be in tile view, as well as etherpad editing.
  93. *
  94. * @param {Object} state - The redux state.
  95. * @returns {boolean} True if tile view should be displayed.
  96. */
  97. export function shouldDisplayTileView(state: Object = {}) {
  98. const participantCount = getParticipantCount(state);
  99. // In case of a lonely meeting, we don't allow tile view.
  100. // But it's a special case too, as we don't even render the button,
  101. // see TileViewButton component.
  102. if (participantCount < 2) {
  103. return false;
  104. }
  105. const tileViewEnabledFeatureFlag = getFeatureFlag(state, TILE_VIEW_ENABLED, true);
  106. const { disableTileView } = state['features/base/config'];
  107. if (disableTileView || !tileViewEnabledFeatureFlag) {
  108. return false;
  109. }
  110. const { tileViewEnabled } = state['features/video-layout'];
  111. if (tileViewEnabled !== undefined) {
  112. // If the user explicitly requested a view mode, we
  113. // do that.
  114. return tileViewEnabled;
  115. }
  116. const { iAmRecorder } = state['features/base/config'];
  117. // None tile view mode is easier to calculate (no need for many negations), so we do
  118. // that and negate it only once.
  119. const shouldDisplayNormalMode = Boolean(
  120. // Reasons for normal mode:
  121. // Editing etherpad
  122. state['features/etherpad']?.editing
  123. // We pinned a participant
  124. || getPinnedParticipant(state)
  125. // It's a 1-on-1 meeting
  126. || participantCount < 3
  127. // There is a shared YouTube video in the meeting
  128. || isVideoPlaying(state)
  129. // We want jibri to use stage view by default
  130. || iAmRecorder
  131. );
  132. return !shouldDisplayNormalMode;
  133. }