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

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