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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // @flow
  2. import { LAYOUTS } from './constants';
  3. import { getPinnedParticipant } from '../base/participants';
  4. import { TILE_ASPECT_RATIO } from '../filmstrip/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 fill
  33. * the available space optimally.
  34. *
  35. * @param {Object} state - The redux store state.
  36. * @returns {Object} An object is return with the desired number of columns,
  37. * rows, and visible rows (the rest should overflow) for the tile view layout.
  38. */
  39. export function getTileViewGridDimensions(state: Object) {
  40. // When in tile view mode, we must discount ourselves (the local participant) because our
  41. // tile is not visible.
  42. const { iAmRecorder } = state['features/base/config'];
  43. var numberOfParticipants = state['features/base/participants'].length - (iAmRecorder ? 1 : 0);
  44. if (window.glob_dev_fns && window.glob_dev_fns.getTileViewGridDimensions_set_num){
  45. const numberOfParticipants_dev = window.glob_dev_fns.getTileViewGridDimensions_set_num(state,maxColumns)
  46. if (typeof(numberOfParticipants_dev)=="number"){numberOfParticipants = numberOfParticipants_dev}
  47. }
  48. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  49. // const aspectRatio = state['features/filmstrip'].TILE_ASPECT_RATIO;
  50. const aspectRatio = 16/9;
  51. let bestColumns = 0;
  52. let bestRows = 1;
  53. let bestTileWidth = 0;
  54. let bestFound = false;
  55. while (!bestFound) {
  56. const columns = bestColumns + 1;
  57. const straightTileWidth = Math.floor(clientWidth / columns);
  58. const rows = Math.ceil(numberOfParticipants / columns);
  59. const straightTileHeight = Math.floor(clientHeight / rows);
  60. const constrainedTileWidth = Math.ceil(straightTileHeight * aspectRatio);
  61. const tileWidth = Math.min(straightTileWidth, constrainedTileWidth);
  62. if (tileWidth > bestTileWidth) {
  63. bestColumns = columns;
  64. bestRows = rows;
  65. bestTileWidth = tileWidth;
  66. } else {
  67. bestFound = true;
  68. }
  69. }
  70. console.log("setpill",{aspectRatio,bestColumns,bestRows})
  71. return {
  72. columns: bestColumns,
  73. visibleRows: bestRows
  74. };
  75. }
  76. /**
  77. * Returns an efficient grid for tiling rectangles of the same size and aspect ratio in a rectangular container.
  78. *
  79. * @param {number} ratio - Ratio of the tile's aspect-ratio / the container's aspect-ratio
  80. * @param {number} tilesParam - the number of tiles to calculate the grid for
  81. * @returns {Object} An object containing the number of rows, columns, rows * columns , and tiles
  82. */
  83. export function calcTileGrid(ratio: number, tilesParam: number) {
  84. let rows = 1;
  85. let columns = 1;
  86. let availableTiles = 1;
  87. let tiles = tilesParam;
  88. // Someone could give you ratio = 0 and/or tiles = Infinity
  89. if (tiles > 65536) {
  90. tiles = 1;
  91. }
  92. while (availableTiles < tiles) {
  93. if ((columns + 1) * ratio < rows + 1) {
  94. columns++;
  95. } else {
  96. rows++;
  97. }
  98. availableTiles = rows * columns;
  99. }
  100. return {
  101. rows,
  102. columns,
  103. availableTiles,
  104. tiles
  105. };
  106. }
  107. /**
  108. * Selector for determining if the UI layout should be in tile view. Tile view
  109. * is determined by more than just having the tile view setting enabled, as
  110. * one-on-one calls should not be in tile view, as well as etherpad editing.
  111. *
  112. * @param {Object} state - The redux state.
  113. * @returns {boolean} True if tile view should be displayed.
  114. */
  115. export function shouldDisplayTileView(state: Object = {}) {
  116. return Boolean(
  117. state['features/video-layout']
  118. && state['features/video-layout'].tileViewEnabled
  119. && (!state['features/etherpad']
  120. || !state['features/etherpad'].editing)
  121. // Truthy check is needed for interfaceConfig to prevent errors on
  122. // mobile which does not have interfaceConfig. On web, tile view
  123. // should never be enabled for filmstrip only mode.
  124. && (typeof interfaceConfig === 'undefined'
  125. || !interfaceConfig.filmStripOnly)
  126. && !getPinnedParticipant(state)
  127. );
  128. }