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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // @flow
  2. import { LAYOUTS } from './constants';
  3. import { getPinnedParticipant } from '../base/participants';
  4. import { TILE_ASPECT_RATIO } from '../video-layout/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 should 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. const { iAmRecorder } = state['features/base/config'];
  97. // const numberOfParticipants = state['features/base/participants'].length - (iAmRecorder ? 1 : 0);
  98. var numberOfParticipants = state['features/base/participants'].length - (iAmRecorder ? 1 : 0);
  99. try {
  100. numberOfParticipants = window.glob_dev_fns.getTileViewGridDimensions_set_num(state,maxColumns)
  101. if (typeof(numberOfParticipants) == "number"){
  102. } else {
  103. }
  104. } catch {
  105. numberOfParticipants = state['features/base/participants'].length - (iAmRecorder ? 1 : 0);
  106. }
  107. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  108. // calculate available width and height for tile view.
  109. // copied from calculateThumbnailSizeForTileView (one variable was dropped)
  110. const topBottomPadding = 200;
  111. const sideMargins = 30 * 2;
  112. const viewWidth = clientWidth - sideMargins
  113. const viewHeight = clientHeight - topBottomPadding
  114. const viewAspectRatio = viewWidth/viewHeight
  115. const ratioOfRatios = TILE_ASPECT_RATIO/viewAspectRatio
  116. var {rows, columns, availableTiles} = calcTileGrid(ratioOfRatios,numberOfParticipants)
  117. // maybe remove a column, for aesthetics
  118. if (rows <= availableTiles - numberOfParticipants){
  119. columns -= 1
  120. }
  121. // var visibleRows = Math.ceil(numberOfParticipants / columns);
  122. const columnsOverflowed = columns > maxColumns
  123. columns = Math.min(columns, maxColumns);
  124. var visibleRows = Math.ceil(numberOfParticipants / columns);
  125. if (columnsOverflowed){
  126. visibleRows = Math.min(visibleRows , maxColumns);
  127. }
  128. // const columnsToMaintainASquare = Math.ceil(Math.sqrt(numberOfParticipants));
  129. // const rows = Math.ceil(numberOfParticipants / columns);
  130. return {
  131. columns,
  132. visibleRows
  133. };
  134. }
  135. /**
  136. * Selector for determining if the UI layout should be in tile view. Tile view
  137. * is determined by more than just having the tile view setting enabled, as
  138. * one-on-one calls should not be in tile view, as well as etherpad editing.
  139. *
  140. * @param {Object} state - The redux state.
  141. * @returns {boolean} True if tile view should be displayed.
  142. */
  143. export function shouldDisplayTileView(state: Object = {}) {
  144. return Boolean(
  145. state['features/video-layout']
  146. && state['features/video-layout'].tileViewEnabled
  147. && (!state['features/etherpad']
  148. || !state['features/etherpad'].editing)
  149. // Truthy check is needed for interfaceConfig to prevent errors on
  150. // mobile which does not have interfaceConfig. On web, tile view
  151. // should never be enabled for filmstrip only mode.
  152. && (typeof interfaceConfig === 'undefined'
  153. || !interfaceConfig.filmStripOnly)
  154. && !getPinnedParticipant(state)
  155. );
  156. }