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.web.js 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {
  2. DEFAULT_MAX_COLUMNS,
  3. ABSOLUTE_MAX_COLUMNS,
  4. TILE_PORTRAIT_ASPECT_RATIO
  5. } from '../filmstrip/constants';
  6. import {
  7. getNumberOfPartipantsForTileView,
  8. getThumbnailMinHeight,
  9. getTileDefaultAspectRatio
  10. } from '../filmstrip/functions';
  11. export * from './functions.any';
  12. declare var interfaceConfig: Object;
  13. /**
  14. * Returns how many columns should be displayed in tile view. The number
  15. * returned will be between 1 and 7, inclusive.
  16. *
  17. * @param {Object} state - The redux store state.
  18. * @param {Object} options - Object with custom values used to override the values that we get from redux by default.
  19. * @param {number} options.width - Custom width to be used.
  20. * @param {boolean} options.disableResponsiveTiles - Custom value to be used instead of config.disableResponsiveTiles.
  21. * @param {boolean} options.disableTileEnlargement - Custom value to be used instead of config.disableTileEnlargement.
  22. * @returns {number}
  23. */
  24. export function getMaxColumnCount(state, options = {}) {
  25. if (typeof interfaceConfig === 'undefined') {
  26. return DEFAULT_MAX_COLUMNS;
  27. }
  28. const {
  29. disableResponsiveTiles: configDisableResponsiveTiles,
  30. disableTileEnlargement: configDisableTileEnlargement
  31. } = state['features/base/config'];
  32. const {
  33. width,
  34. disableResponsiveTiles = configDisableResponsiveTiles,
  35. disableTileEnlargement = configDisableTileEnlargement
  36. } = options;
  37. const { clientWidth } = state['features/base/responsive-ui'];
  38. const widthToUse = width || clientWidth;
  39. const configuredMax = interfaceConfig.TILE_VIEW_MAX_COLUMNS;
  40. if (disableResponsiveTiles) {
  41. return Math.min(Math.max(configuredMax || DEFAULT_MAX_COLUMNS, 1), ABSOLUTE_MAX_COLUMNS);
  42. }
  43. if (typeof interfaceConfig.TILE_VIEW_MAX_COLUMNS !== 'undefined' && interfaceConfig.TILE_VIEW_MAX_COLUMNS > 0) {
  44. return Math.max(configuredMax, 1);
  45. }
  46. const aspectRatio = disableTileEnlargement
  47. ? getTileDefaultAspectRatio(true, disableTileEnlargement, widthToUse)
  48. : TILE_PORTRAIT_ASPECT_RATIO;
  49. const minHeight = getThumbnailMinHeight(widthToUse);
  50. const minWidth = aspectRatio * minHeight;
  51. return Math.floor(widthToUse / minWidth);
  52. }
  53. /**
  54. * Returns the cell count dimensions for tile view. Tile view tries to uphold
  55. * equal count of tiles for height and width, until maxColumn is reached in
  56. * which rows will be added but no more columns.
  57. *
  58. * @param {Object} state - The redux store state.
  59. * @param {boolean} stageFilmstrip - Whether the dimensions should be calculated for the stage filmstrip.
  60. * @returns {Object} An object is return with the desired number of columns,
  61. * rows, and visible rows (the rest should overflow) for the tile view layout.
  62. */
  63. export function getNotResponsiveTileViewGridDimensions(state: Object, stageFilmstrip: boolean = false) {
  64. const maxColumns = getMaxColumnCount(state);
  65. const { activeParticipants } = state['features/filmstrip'];
  66. const numberOfParticipants = stageFilmstrip ? activeParticipants.length : getNumberOfPartipantsForTileView(state);
  67. const columnsToMaintainASquare = Math.ceil(Math.sqrt(numberOfParticipants));
  68. const columns = Math.min(columnsToMaintainASquare, maxColumns);
  69. const rows = Math.ceil(numberOfParticipants / columns);
  70. const minVisibleRows = Math.min(maxColumns, rows);
  71. return {
  72. columns,
  73. minVisibleRows,
  74. rows
  75. };
  76. }