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

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