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

functions.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.max(Math.min(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 {number} numberOfParticipants - The number of participants including the fake participants.
  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(numberOfParticipants: number, maxColumns: number = getMaxColumnCount()) {
  42. const columnsToMaintainASquare = Math.ceil(Math.sqrt(numberOfParticipants));
  43. const columns = Math.min(columnsToMaintainASquare, maxColumns);
  44. const rows = Math.ceil(numberOfParticipants / columns);
  45. const visibleRows = Math.min(maxColumns, rows);
  46. return {
  47. columns,
  48. visibleRows
  49. };
  50. }
  51. /**
  52. * Selector for determining if the UI layout should be in tile view. Tile view
  53. * is determined by more than just having the tile view setting enabled, as
  54. * one-on-one calls should not be in tile view, as well as etherpad editing.
  55. *
  56. * @param {Object} state - The redux state.
  57. * @returns {boolean} True if tile view should be displayed.
  58. */
  59. export function shouldDisplayTileView(state: Object = {}) {
  60. return Boolean(
  61. state['features/video-layout']
  62. && state['features/video-layout'].tileViewEnabled
  63. && (!state['features/etherpad']
  64. || !state['features/etherpad'].editing)
  65. // Truthy check is needed for interfaceConfig to prevent errors on
  66. // mobile which does not have interfaceConfig. On web, tile view
  67. // should never be enabled for filmstrip only mode.
  68. && (typeof interfaceConfig === 'undefined'
  69. || !interfaceConfig.filmStripOnly)
  70. && !getPinnedParticipant(state)
  71. );
  72. }