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

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