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

functions.js 2.9KB

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