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

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