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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // @flow
  2. import { LAYOUTS } from './constants';
  3. import { getPinnedParticipant } from '../base/participants';
  4. declare var interfaceConfig: Object;
  5. /**
  6. * Returns the {@code LAYOUTS} constant associated with the layout
  7. * the application should currently be in.
  8. *
  9. * @param {Object} state - The redux state.
  10. * @returns {string}
  11. */
  12. export function getCurrentLayout(state: Object) {
  13. if (shouldDisplayTileView(state)) {
  14. return LAYOUTS.TILE_VIEW;
  15. } else if (interfaceConfig.VERTICAL_FILMSTRIP) {
  16. return LAYOUTS.VERTICAL_FILMSTRIP_VIEW;
  17. }
  18. return LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW;
  19. }
  20. /**
  21. * Returns how many columns should be displayed in tile view. The number
  22. * returned will be between 1 and 5, inclusive.
  23. *
  24. * @returns {number}
  25. */
  26. export function getMaxColumnCount() {
  27. const configuredMax = interfaceConfig.TILE_VIEW_MAX_COLUMNS || 5;
  28. return Math.min(Math.max(configuredMax, 1), 5);
  29. }
  30. /**
  31. * Returns the cell count dimensions for tile view. Tile view tries to uphold
  32. * equal count of tiles for height and width, until maxColumn is reached in
  33. * which rows will be added but no more columns.
  34. *
  35. * @param {Object} state - The redux store state.
  36. * @param {number} maxColumns - The maximum number of columns that can be
  37. * displayed.
  38. * @returns {Object} An object is return with the desired number of columns,
  39. * rows, and visible rows (the rest should overflow) for the tile view layout.
  40. */
  41. export function getTileViewGridDimensions(state: Object, maxColumns: number = getMaxColumnCount()) {
  42. // When in tile view mode, we must discount ourselves (the local participant) because our
  43. // tile is not visible.
  44. const { iAmRecorder } = state['features/base/config'];
  45. const numberOfParticipants = state['features/base/participants'].length - (iAmRecorder ? 1 : 0);
  46. const columnsToMaintainASquare = Math.ceil(Math.sqrt(numberOfParticipants));
  47. const columns = Math.min(columnsToMaintainASquare, maxColumns);
  48. const rows = Math.ceil(numberOfParticipants / columns);
  49. const visibleRows = Math.min(maxColumns, rows);
  50. return {
  51. columns,
  52. visibleRows
  53. };
  54. }
  55. /**
  56. * Selector for determining if the UI layout should be in tile view. Tile view
  57. * is determined by more than just having the tile view setting enabled, as
  58. * one-on-one calls should not be in tile view, as well as etherpad editing.
  59. *
  60. * @param {Object} state - The redux state.
  61. * @returns {boolean} True if tile view should be displayed.
  62. */
  63. export function shouldDisplayTileView(state: Object = {}) {
  64. return Boolean(
  65. state['features/video-layout']
  66. && state['features/video-layout'].tileViewEnabled
  67. && (!state['features/etherpad']
  68. || !state['features/etherpad'].editing)
  69. // Truthy check is needed for interfaceConfig to prevent errors on
  70. // mobile which does not have interfaceConfig. On web, tile view
  71. // should never be enabled for filmstrip only mode.
  72. && (typeof interfaceConfig === 'undefined'
  73. || !interfaceConfig.filmStripOnly)
  74. && !getPinnedParticipant(state)
  75. );
  76. }