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 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // @flow
  2. import { JitsiParticipantConnectionStatus } from '../base/lib-jitsi-meet';
  3. import { MEDIA_TYPE } from '../base/media';
  4. import {
  5. getLocalParticipant,
  6. getParticipantById,
  7. getParticipantCountWithFake,
  8. getPinnedParticipant
  9. } from '../base/participants';
  10. import { toState } from '../base/redux';
  11. import {
  12. getLocalVideoTrack,
  13. getTrackByMediaTypeAndParticipant,
  14. isLocalTrackMuted,
  15. isRemoteTrackMuted
  16. } from '../base/tracks/functions';
  17. import { ASPECT_RATIO_BREAKPOINT, SQUARE_TILE_ASPECT_RATIO, TILE_ASPECT_RATIO } from './constants';
  18. declare var interfaceConfig: Object;
  19. // Minimum space to keep between the sides of the tiles and the sides
  20. // of the window.
  21. const TILE_VIEW_SIDE_MARGINS = 20;
  22. /**
  23. * Returns true if the filmstrip on mobile is visible, false otherwise.
  24. *
  25. * NOTE: Filmstrip on web behaves differently to mobile, much simpler, but so
  26. * function lies here only for the sake of consistency and to avoid flow errors
  27. * on import.
  28. *
  29. * @param {Object | Function} stateful - The Object or Function that can be
  30. * resolved to a Redux state object with the toState function.
  31. * @returns {boolean}
  32. */
  33. export function isFilmstripVisible(stateful: Object | Function) {
  34. return toState(stateful)['features/filmstrip'].visible;
  35. }
  36. /**
  37. * Determines whether the remote video thumbnails should be displayed/visible in
  38. * the filmstrip.
  39. *
  40. * @param {Object} state - The full redux state.
  41. * @returns {boolean} - If remote video thumbnails should be displayed/visible
  42. * in the filmstrip, then {@code true}; otherwise, {@code false}.
  43. */
  44. export function shouldRemoteVideosBeVisible(state: Object) {
  45. if (state['features/invite'].calleeInfoVisible) {
  46. return false;
  47. }
  48. // Include fake participants to derive how many thumbnails are dispalyed,
  49. // as it is assumed all participants, including fake, will be displayed
  50. // in the filmstrip.
  51. const participantCount = getParticipantCountWithFake(state);
  52. let pinnedParticipant;
  53. return Boolean(
  54. participantCount > 2
  55. // Always show the filmstrip when there is another participant to
  56. // show and the local video is pinned, or the toolbar is displayed.
  57. || (participantCount > 1
  58. && (state['features/toolbox'].visible
  59. || ((pinnedParticipant = getPinnedParticipant(state))
  60. && pinnedParticipant.local)))
  61. || state['features/base/config'].disable1On1Mode);
  62. }
  63. /**
  64. * Checks whether there is a playable video stream available for the user associated with the passed ID.
  65. *
  66. * @param {Object | Function} stateful - The Object or Function that can be
  67. * resolved to a Redux state object with the toState function.
  68. * @param {string} id - The id of the participant.
  69. * @returns {boolean} <tt>true</tt> if there is a playable video stream available
  70. * or <tt>false</tt> otherwise.
  71. */
  72. export function isVideoPlayable(stateful: Object | Function, id: String) {
  73. const state = toState(stateful);
  74. const tracks = state['features/base/tracks'];
  75. const participant = id ? getParticipantById(state, id) : getLocalParticipant(state);
  76. const isLocal = participant?.local ?? true;
  77. const { connectionStatus } = participant || {};
  78. const videoTrack
  79. = isLocal ? getLocalVideoTrack(tracks) : getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
  80. const isAudioOnly = Boolean(state['features/base/audio-only'].enabled);
  81. let isPlayable = false;
  82. if (isLocal) {
  83. const isVideoMuted = isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO);
  84. isPlayable = Boolean(videoTrack) && !isVideoMuted && !isAudioOnly;
  85. } else if (!participant?.isFakeParticipant) { // remote participants excluding shared video
  86. const isVideoMuted = isRemoteTrackMuted(tracks, MEDIA_TYPE.VIDEO, id);
  87. isPlayable = Boolean(videoTrack) && !isVideoMuted && !isAudioOnly
  88. && connectionStatus === JitsiParticipantConnectionStatus.ACTIVE;
  89. }
  90. return isPlayable;
  91. }
  92. /**
  93. * Calculates the size for thumbnails when in horizontal view layout.
  94. *
  95. * @param {number} clientHeight - The height of the app window.
  96. * @returns {{local: {height, width}, remote: {height, width}}}
  97. */
  98. export function calculateThumbnailSizeForHorizontalView(clientHeight: number = 0) {
  99. const topBottomMargin = 15;
  100. const availableHeight = Math.min(clientHeight, (interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120) + topBottomMargin);
  101. const height = availableHeight - topBottomMargin;
  102. return {
  103. local: {
  104. height,
  105. width: Math.floor(interfaceConfig.LOCAL_THUMBNAIL_RATIO * height)
  106. },
  107. remote: {
  108. height,
  109. width: Math.floor(interfaceConfig.REMOTE_THUMBNAIL_RATIO * height)
  110. }
  111. };
  112. }
  113. /**
  114. * Calculates the size for thumbnails when in tile view layout.
  115. *
  116. * @param {Object} dimensions - The desired dimensions of the tile view grid.
  117. * @returns {{height, width}}
  118. */
  119. export function calculateThumbnailSizeForTileView({
  120. columns,
  121. visibleRows,
  122. clientWidth,
  123. clientHeight,
  124. disableResponsiveTiles
  125. }: Object) {
  126. let aspectRatio = TILE_ASPECT_RATIO;
  127. if (!disableResponsiveTiles && clientWidth < ASPECT_RATIO_BREAKPOINT) {
  128. aspectRatio = SQUARE_TILE_ASPECT_RATIO;
  129. }
  130. const viewWidth = clientWidth - TILE_VIEW_SIDE_MARGINS;
  131. const viewHeight = clientHeight - TILE_VIEW_SIDE_MARGINS;
  132. const initialWidth = viewWidth / columns;
  133. const aspectRatioHeight = initialWidth / aspectRatio;
  134. const height = Math.floor(Math.min(aspectRatioHeight, viewHeight / visibleRows));
  135. const width = Math.floor(aspectRatio * height);
  136. return {
  137. height,
  138. width
  139. };
  140. }
  141. /**
  142. * Returns the width of the visible area (doesn't include the left margin/padding) of the the vertical filmstrip.
  143. *
  144. * @returns {number} - The width of the vertical filmstrip.
  145. */
  146. export function getVerticalFilmstripVisibleAreaWidth() {
  147. // Adding 11px for the 2px right margin, 2px borders on the left and right and 5px right padding.
  148. // Also adding 7px for the scrollbar. Note that we are not counting the left margins and paddings because this
  149. // function is used for calculating the available space and they are invisible.
  150. // TODO: Check if we can remove the left margins and paddings from the CSS.
  151. // FIXME: This function is used to calculate the size of the large video, etherpad or shared video. Once everything
  152. // is reactified this calculation will need to move to the corresponding components.
  153. const filmstripMaxWidth = (interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120) + 18;
  154. return Math.min(filmstripMaxWidth, window.innerWidth);
  155. }