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

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