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.web.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // @flow
  2. import {
  3. getParticipantCountWithFake,
  4. getPinnedParticipant
  5. } from '../base/participants';
  6. import { toState } from '../base/redux';
  7. import { TILE_ASPECT_RATIO } from './constants';
  8. declare var interfaceConfig: Object;
  9. // Minimum space to keep between the sides of the tiles and the sides
  10. // of the window.
  11. const TILE_VIEW_SIDE_MARGINS = 20;
  12. /**
  13. * Returns true if the filmstrip on mobile is visible, false otherwise.
  14. *
  15. * NOTE: Filmstrip on web behaves differently to mobile, much simpler, but so
  16. * function lies here only for the sake of consistency and to avoid flow errors
  17. * on import.
  18. *
  19. * @param {Object | Function} stateful - The Object or Function that can be
  20. * resolved to a Redux state object with the toState function.
  21. * @returns {boolean}
  22. */
  23. export function isFilmstripVisible(stateful: Object | Function) {
  24. return toState(stateful)['features/filmstrip'].visible;
  25. }
  26. /**
  27. * Determines whether the remote video thumbnails should be displayed/visible in
  28. * the filmstrip.
  29. *
  30. * @param {Object} state - The full redux state.
  31. * @returns {boolean} - If remote video thumbnails should be displayed/visible
  32. * in the filmstrip, then {@code true}; otherwise, {@code false}.
  33. */
  34. export function shouldRemoteVideosBeVisible(state: Object) {
  35. if (state['features/invite'].calleeInfoVisible) {
  36. return false;
  37. }
  38. // Include fake participants to derive how many thumbnails are dispalyed,
  39. // as it is assumed all participants, including fake, will be displayed
  40. // in the filmstrip.
  41. const participantCount = getParticipantCountWithFake(state);
  42. let pinnedParticipant;
  43. return Boolean(
  44. participantCount > 2
  45. // Always show the filmstrip when there is another participant to
  46. // show and the filmstrip is hovered, or local video is pinned, or
  47. // the toolbar is displayed.
  48. || (participantCount > 1
  49. && (state['features/filmstrip'].hovered
  50. || state['features/toolbox'].visible
  51. || ((pinnedParticipant = getPinnedParticipant(state))
  52. && pinnedParticipant.local)))
  53. || state['features/base/config'].disable1On1Mode);
  54. }
  55. /**
  56. * Calculates the size for thumbnails when in horizontal view layout.
  57. *
  58. * @param {number} clientHeight - The height of the app window.
  59. * @returns {{local: {height, width}, remote: {height, width}}}
  60. */
  61. export function calculateThumbnailSizeForHorizontalView(clientHeight: number = 0) {
  62. const topBottomMargin = 15;
  63. const availableHeight = Math.min(clientHeight, (interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120) + topBottomMargin);
  64. const height = availableHeight - topBottomMargin;
  65. return {
  66. local: {
  67. height,
  68. width: Math.floor(interfaceConfig.LOCAL_THUMBNAIL_RATIO * height)
  69. },
  70. remote: {
  71. height,
  72. width: Math.floor(interfaceConfig.REMOTE_THUMBNAIL_RATIO * height)
  73. }
  74. };
  75. }
  76. /**
  77. * Calculates the size for thumbnails when in tile view layout.
  78. *
  79. * @param {Object} dimensions - The desired dimensions of the tile view grid.
  80. * @returns {{height, width}}
  81. */
  82. export function calculateThumbnailSizeForTileView({
  83. columns,
  84. visibleRows,
  85. clientWidth,
  86. clientHeight
  87. }: Object) {
  88. const viewWidth = clientWidth - TILE_VIEW_SIDE_MARGINS;
  89. const viewHeight = clientHeight - TILE_VIEW_SIDE_MARGINS;
  90. const initialWidth = viewWidth / columns;
  91. const aspectRatioHeight = initialWidth / TILE_ASPECT_RATIO;
  92. const height = Math.floor(Math.min(aspectRatioHeight, viewHeight / visibleRows));
  93. const width = Math.floor(TILE_ASPECT_RATIO * height);
  94. return {
  95. height,
  96. width
  97. };
  98. }
  99. /**
  100. * Returns the width of the visible area (doesn't include the left margin/padding) of the the vertical filmstrip.
  101. *
  102. * @returns {number} - The width of the vertical filmstrip.
  103. */
  104. export function getVerticalFilmstripVisibleAreaWidth() {
  105. // Adding 11px for the 2px right margin, 2px borders on the left and right and 5px right padding.
  106. // Also adding 7px for the scrollbar. Note that we are not counting the left margins and paddings because this
  107. // function is used for calculating the available space and they are invisible.
  108. // TODO: Check if we can remove the left margins and paddings from the CSS.
  109. // FIXME: This function is used to calculate the size of the large video, etherpad or shared video. Once everything
  110. // is reactified this calculation will need to move to the corresponding components.
  111. const filmstripMaxWidth = (interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120) + 18;
  112. return Math.min(filmstripMaxWidth, window.innerWidth);
  113. }