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

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