您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.js 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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_setpill(state: Object) {
  40. export function getTileViewGridDimensions(state: Object) {
  41. // When in tile view mode, we must discount ourselves (the local participant) because our
  42. // tile is not visible.
  43. const { iAmRecorder } = state['features/base/config'];
  44. var numberOfParticipants = state['features/base/participants'].length - (iAmRecorder ? 1 : 0);
  45. if (window.glob_dev_fns && window.glob_dev_fns.getTileViewGridDimensions_set_num){
  46. const numberOfParticipants_dev = window.glob_dev_fns.getTileViewGridDimensions_set_num(state)
  47. if (typeof(numberOfParticipants_dev)=="number"){numberOfParticipants = numberOfParticipants_dev}
  48. }
  49. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  50. // const aspectRatio = state['features/filmstrip'].TILE_ASPECT_RATIO;
  51. const aspectRatio = 16/9;
  52. let bestColumns = 0;
  53. let bestRows = 1;
  54. let bestTileWidth = 0;
  55. let bestFound = false;
  56. while (!bestFound) {
  57. const columns = bestColumns + 1;
  58. const straightTileWidth = Math.floor(clientWidth / columns);
  59. const rows = Math.ceil(numberOfParticipants / columns);
  60. const straightTileHeight = Math.floor(clientHeight / rows);
  61. const constrainedTileWidth = Math.ceil(straightTileHeight * aspectRatio);
  62. const tileWidth = Math.min(straightTileWidth, constrainedTileWidth);
  63. if (tileWidth > bestTileWidth) {
  64. bestColumns = columns;
  65. bestRows = rows;
  66. bestTileWidth = tileWidth;
  67. } else {
  68. bestFound = true;
  69. }
  70. }
  71. console.log("pull_req setpill",{aspectRatio,numberOfParticipants,bestColumns,bestRows})
  72. return {
  73. columns: bestColumns,
  74. visibleRows: bestRows
  75. };
  76. }
  77. /**
  78. * Returns the cell count dimensions for tile view. Tile view tries to
  79. * maximize the size of the tiles, until maxColumn is reached in
  80. * which rows will be added but no more columns.
  81. *
  82. * @param {Object} state - The redux store state.
  83. * @param {number} maxColumns - The maximum number of columns that can be
  84. * displayed.
  85. * @returns {Object} An object is return with the desired number of columns,
  86. * rows, and visible rows (the rest might overflow) for the tile view layout.
  87. */
  88. // export function getTileViewGridDimensions(state: Object, maxColumns: number = getMaxColumnCount()) {
  89. export function getTileViewGridDimensions_jfinn(state: Object, maxColumns: number = getMaxColumnCount()) {
  90. // When in tile view mode, we must discount ourselves (the local participant) because our
  91. // tile is not visible.
  92. const { iAmRecorder } = state['features/base/config'];
  93. var numberOfParticipants0 = state['features/base/participants'].length - (iAmRecorder ? 1 : 0);
  94. var numberOfParticipants = state['features/base/participants'].length - (iAmRecorder ? 1 : 0);
  95. if (window.glob_dev_fns && window.glob_dev_fns.getTileViewGridDimensions_set_num){
  96. const numberOfParticipants_dev = window.glob_dev_fns.getTileViewGridDimensions_set_num(state)
  97. if (typeof(numberOfParticipants_dev)=="number"){numberOfParticipants = numberOfParticipants_dev}
  98. }
  99. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  100. // calculate available width and height for tile view.
  101. // copied from calculateThumbnailSizeForTileView (one variable was dropped)
  102. const topBottomPadding = 200;
  103. const sideMargins = 30 * 2;
  104. const viewWidth = clientWidth - sideMargins;
  105. const viewHeight = clientHeight - topBottomPadding;
  106. const viewAspectRatio = viewWidth / viewHeight;
  107. const ratioOfRatios = TILE_ASPECT_RATIO / viewAspectRatio;
  108. const tileGrid = calcTileGrid(ratioOfRatios, numberOfParticipants);
  109. let { columns } = tileGrid;
  110. const { rows, availableTiles } = tileGrid;
  111. // maybe remove a column, for aesthetics.
  112. if (rows <= availableTiles - numberOfParticipants) {
  113. columns -= 1;
  114. }
  115. const columnsOverflowed = columns > maxColumns;
  116. columns = Math.min(columns, maxColumns);
  117. let visibleRows = Math.ceil(numberOfParticipants / columns);
  118. if (columnsOverflowed) {
  119. visibleRows = Math.min(visibleRows, maxColumns);
  120. }
  121. console.log("pull_req jfinn dev",{TILE_ASPECT_RATIO,tileGrid,numberOfParticipants0,numberOfParticipants,columns,visibleRows})
  122. return {
  123. columns,
  124. visibleRows
  125. };
  126. }
  127. /**
  128. * Returns an efficient grid for tiling rectangles of the same size and aspect ratio in a rectangular container.
  129. *
  130. * @param {number} ratio - Ratio of the tile's aspect-ratio / the container's aspect-ratio
  131. * @param {number} tilesParam - the number of tiles to calculate the grid for
  132. * @returns {Object} An object containing the number of rows, columns, rows * columns , and tiles
  133. */
  134. export function calcTileGrid(ratio: number, tilesParam: number) {
  135. let rows = 1;
  136. let columns = 1;
  137. let availableTiles = 1;
  138. let tiles = tilesParam;
  139. // Someone could give you ratio = 0 and/or tiles = Infinity
  140. if (tiles > 65536) {
  141. tiles = 1;
  142. }
  143. while (availableTiles < tiles) {
  144. if ((columns + 1) * ratio < rows + 1) {
  145. columns++;
  146. } else {
  147. rows++;
  148. }
  149. availableTiles = rows * columns;
  150. }
  151. return {
  152. rows,
  153. columns,
  154. availableTiles,
  155. tiles
  156. };
  157. }
  158. /**
  159. * Selector for determining if the UI layout should be in tile view. Tile view
  160. * is determined by more than just having the tile view setting enabled, as
  161. * one-on-one calls should not be in tile view, as well as etherpad editing.
  162. *
  163. * @param {Object} state - The redux state.
  164. * @returns {boolean} True if tile view should be displayed.
  165. */
  166. export function shouldDisplayTileView(state: Object = {}) {
  167. return Boolean(
  168. state['features/video-layout']
  169. && state['features/video-layout'].tileViewEnabled
  170. && (!state['features/etherpad']
  171. || !state['features/etherpad'].editing)
  172. // Truthy check is needed for interfaceConfig to prevent errors on
  173. // mobile which does not have interfaceConfig. On web, tile view
  174. // should never be enabled for filmstrip only mode.
  175. && (typeof interfaceConfig === 'undefined'
  176. || !interfaceConfig.filmStripOnly)
  177. && !getPinnedParticipant(state)
  178. );
  179. }