Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

functions.web.js 10KB

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