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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // @flow
  2. import { getPinnedParticipant } from '../base/participants';
  3. import { TILE_ASPECT_RATIO } from '../filmstrip/constants';
  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
  33. * maximize the size of the tiles, 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 might 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. try {
  46. var fn_ret = glob_dev_fns.getTileViewGridDimensions(...arguments,maxColumns)
  47. if (fn_ret){
  48. return fn_ret.ret
  49. }
  50. } catch (err) {
  51. clog("react_fn err:",err)
  52. }
  53. clog("getTileViewGridDimensions",this)
  54. const { iAmRecorder } = state['features/base/config'];
  55. // dev util hook
  56. // const numberOfParticipants = state['features/base/participants'].length - (iAmRecorder ? 1 : 0);
  57. // /*
  58. var numberOfParticipants = state['features/base/participants'].length - (iAmRecorder ? 1 : 0);
  59. // clog("r0 num",numberOfParticipants)
  60. if (window.glob_dev_fns && window.glob_dev_fns.getTileViewGridDimensions_set_num){
  61. const numberOfParticipants_dev = window.glob_dev_fns.getTileViewGridDimensions_set_num(state,maxColumns,numberOfParticipants)
  62. if (typeof(numberOfParticipants_dev)=="number"){numberOfParticipants = numberOfParticipants_dev}
  63. }
  64. // */
  65. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  66. // calculate available width and height for tile view.
  67. // copied from calculateThumbnailSizeForTileView (one variable was dropped)
  68. const topBottomPadding = 200;
  69. const sideMargins = 30 * 2;
  70. const viewWidth = clientWidth - sideMargins;
  71. const viewHeight = clientHeight - topBottomPadding;
  72. const viewAspectRatio = viewWidth / viewHeight;
  73. const ratioOfRatios = TILE_ASPECT_RATIO / viewAspectRatio;
  74. const tileGrid = calcTileGrid(ratioOfRatios, numberOfParticipants);
  75. let { columns } = tileGrid;
  76. const { rows, availableTiles } = tileGrid;
  77. // maybe remove a column, for aesthetics.
  78. // clog("r0 dec? columns",columns,rows <= availableTiles - numberOfParticipants,columns > 1,rows <= availableTiles - numberOfParticipants && columns > 1)
  79. // if (rows <= availableTiles - numberOfParticipants && columns > 1) {
  80. if (rows <= availableTiles - numberOfParticipants) {
  81. // clog("r0 dec columns",columns)
  82. columns -= 1;
  83. // clog("r0 dec columns2",columns)
  84. }
  85. const columnsOverflowed = columns > maxColumns;
  86. // clog("r0 NaN",columnsOverflowed,Math.ceil(numberOfParticipants / columns),Math.min(columns, maxColumns) )
  87. // clog("r0 NaN2",Math.min(Math.ceil(numberOfParticipants / columns),maxColumns))
  88. columns = Math.min(columns, maxColumns) || 1;
  89. let visibleRows = Math.ceil(numberOfParticipants / columns) || 1;
  90. if (columnsOverflowed) {
  91. visibleRows = Math.min(visibleRows, maxColumns);
  92. }
  93. // clog("r0 gtvd",{columns,visibleRows,numberOfParticipants},tileGrid)
  94. return {
  95. columns,
  96. visibleRows
  97. };
  98. }
  99. /**
  100. * Returns an efficient grid for tiling rectangles of the same size and aspect ratio in a rectangular container.
  101. *
  102. * @param {number} ratio - Ratio of the tile's aspect-ratio / the container's aspect-ratio
  103. * @param {number} tilesParam - the number of tiles to calculate the grid for
  104. * @returns {Object} An object containing the number of rows, columns, rows * columns , and tiles
  105. */
  106. export function calcTileGrid(ratio: number, tilesParam: number) {
  107. let rows = 1;
  108. let columns = 1;
  109. let availableTiles = 1;
  110. let tiles = tilesParam;
  111. // Someone could give you ratio = 0 and/or tiles = Infinity
  112. if (tiles > 65536) {
  113. tiles = 1;
  114. }
  115. while (availableTiles < tiles) {
  116. if ((columns + 1) * ratio < rows + 1) {
  117. columns++;
  118. } else {
  119. rows++;
  120. }
  121. availableTiles = rows * columns;
  122. }
  123. return {
  124. rows,
  125. columns,
  126. availableTiles,
  127. tiles
  128. };
  129. }
  130. /**
  131. * Selector for determining if the UI layout should be in tile view. Tile view
  132. * is determined by more than just having the tile view setting enabled, as
  133. * one-on-one calls should not be in tile view, as well as etherpad editing.
  134. *
  135. * @param {Object} state - The redux state.
  136. * @returns {boolean} True if tile view should be displayed.
  137. */
  138. export function shouldDisplayTileView(state: Object = {}) {
  139. return Boolean(
  140. state['features/video-layout']
  141. && state['features/video-layout'].tileViewEnabled
  142. && (!state['features/etherpad']
  143. || !state['features/etherpad'].editing)
  144. // Truthy check is needed for interfaceConfig to prevent errors on
  145. // mobile which does not have interfaceConfig. On web, tile view
  146. // should never be enabled for filmstrip only mode.
  147. && (typeof interfaceConfig === 'undefined'
  148. || !interfaceConfig.filmStripOnly)
  149. && !getPinnedParticipant(state)
  150. );
  151. }