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

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