Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

functions.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // @flow
  2. import { LAYOUTS } from './constants';
  3. import { getPinnedParticipant } from '../base/participants';
  4. declare var interfaceConfig: Object;
  5. /**
  6. * Returns the {@code LAYOUTS} constant associated with the layout
  7. * the application should currently be in.
  8. *
  9. * @param {Object} state - The redux state.
  10. * @returns {string}
  11. */
  12. export function getCurrentLayout(state: Object) {
  13. if (shouldDisplayTileView(state)) {
  14. return LAYOUTS.TILE_VIEW;
  15. } else if (interfaceConfig.VERTICAL_FILMSTRIP) {
  16. return LAYOUTS.VERTICAL_FILMSTRIP_VIEW;
  17. }
  18. return LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW;
  19. }
  20. /**
  21. * Returns how many columns should be displayed in tile view. The number
  22. * returned will be between 1 and 5, inclusive.
  23. *
  24. * @returns {number}
  25. */
  26. export function getMaxColumnCount() {
  27. const configuredMax = interfaceConfig.TILE_VIEW_MAX_COLUMNS || 5;
  28. return Math.min(Math.max(configuredMax, 1), 5);
  29. }
  30. /**
  31. * Returns the cell count dimensions for tile view. Tile view tries to uphold
  32. * equal count of tiles for height and width, until maxColumn is reached in
  33. * which rows will be added but no more columns.
  34. *
  35. * @param {Object} state - The redux store state.
  36. * @param {number} maxColumns - The maximum number of columns that can be
  37. * displayed.
  38. * @returns {Object} An object is return with the desired number of columns,
  39. * rows, and visible rows (the rest should overflow) for the tile view layout.
  40. */
  41. export function getTileViewGridDimensions(state: Object, maxColumns: number = getMaxColumnCount()) {
  42. // When in tile view mode, we must discount ourselves (the local participant) because our
  43. // tile is not visible.
  44. const { iAmRecorder } = state['features/base/config'];
  45. const numberOfParticipants = state['features/base/participants'].length - (iAmRecorder ? 1 : 0);
  46. // dev hook
  47. var columnsToMaintainASquare
  48. if (window.glob_dev_fns){
  49. if (window.glob_dev_fns.getTileViewGridDimensions){
  50. var ret = window.glob_dev_fns.getTileViewGridDimensions(numberOfParticipants,state,maxColumns)
  51. return ret
  52. } else if (window.glob_dev_fns.getTileViewGridDimensions_sq){
  53. columnsToMaintainASquare = window.glob_dev_fns.getTileViewGridDimensions_sq(numberOfParticipants,state,maxColumns)
  54. }
  55. if (typeof(columnsToMaintainASquare) != "number"){
  56. columnsToMaintainASquare = Math.ceil(Math.sqrt(numberOfParticipants));
  57. }
  58. } else {
  59. columnsToMaintainASquare = Math.ceil(Math.sqrt(numberOfParticipants));
  60. }
  61. // const columnsToMaintainASquare = Math.ceil(Math.sqrt(numberOfParticipants));
  62. const columns = Math.min(columnsToMaintainASquare, maxColumns);
  63. const rows = Math.ceil(numberOfParticipants / columns);
  64. const visibleRows = Math.min(maxColumns, rows);
  65. return {
  66. columns,
  67. visibleRows
  68. };
  69. }
  70. /**
  71. * Selector for determining if the UI layout should be in tile view. Tile view
  72. * is determined by more than just having the tile view setting enabled, as
  73. * one-on-one calls should not be in tile view, as well as etherpad editing.
  74. *
  75. * @param {Object} state - The redux state.
  76. * @returns {boolean} True if tile view should be displayed.
  77. */
  78. export function shouldDisplayTileView(state: Object = {}) {
  79. return Boolean(
  80. state['features/video-layout']
  81. && state['features/video-layout'].tileViewEnabled
  82. && (!state['features/etherpad']
  83. || !state['features/etherpad'].editing)
  84. // Truthy check is needed for interfaceConfig to prevent errors on
  85. // mobile which does not have interfaceConfig. On web, tile view
  86. // should never be enabled for filmstrip only mode.
  87. && (typeof interfaceConfig === 'undefined'
  88. || !interfaceConfig.filmStripOnly)
  89. && !getPinnedParticipant(state)
  90. );
  91. }