Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

functions.web.js 8.1KB

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