Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

functions.web.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 filmstrip is hovered, or local video is pinned, or
  57. // the toolbar is displayed.
  58. || (participantCount > 1
  59. && (state['features/filmstrip'].hovered
  60. || state['features/toolbox'].visible
  61. || ((pinnedParticipant = getPinnedParticipant(state))
  62. && pinnedParticipant.local)))
  63. || state['features/base/config'].disable1On1Mode);
  64. }
  65. /**
  66. * Checks whether there is a playable video stream available for the user associated with the passed ID.
  67. *
  68. * @param {Object | Function} stateful - The Object or Function that can be
  69. * resolved to a Redux state object with the toState function.
  70. * @param {string} id - The id of the participant.
  71. * @returns {boolean} <tt>true</tt> if there is a playable video stream available
  72. * or <tt>false</tt> otherwise.
  73. */
  74. export function isVideoPlayable(stateful: Object | Function, id: String) {
  75. const state = toState(stateful);
  76. const tracks = state['features/base/tracks'];
  77. const participant = id ? getParticipantById(state, id) : getLocalParticipant(state);
  78. const isLocal = participant?.local ?? true;
  79. const { connectionStatus } = participant || {};
  80. const videoTrack
  81. = isLocal ? getLocalVideoTrack(tracks) : getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, id);
  82. const isAudioOnly = Boolean(state['features/base/audio-only'].enabled);
  83. let isPlayable = false;
  84. if (isLocal) {
  85. const isVideoMuted = isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO);
  86. isPlayable = Boolean(videoTrack) && !isVideoMuted && !isAudioOnly;
  87. } else if (!participant?.isFakeParticipant) { // remote participants excluding shared video
  88. const isVideoMuted = isRemoteTrackMuted(tracks, MEDIA_TYPE.VIDEO, id);
  89. isPlayable = Boolean(videoTrack) && !isVideoMuted && !isAudioOnly
  90. && connectionStatus === JitsiParticipantConnectionStatus.ACTIVE;
  91. }
  92. return isPlayable;
  93. }
  94. /**
  95. * Calculates the size for thumbnails when in horizontal view layout.
  96. *
  97. * @param {number} clientHeight - The height of the app window.
  98. * @returns {{local: {height, width}, remote: {height, width}}}
  99. */
  100. export function calculateThumbnailSizeForHorizontalView(clientHeight: number = 0) {
  101. const topBottomMargin = 15;
  102. const availableHeight = Math.min(clientHeight, (interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120) + topBottomMargin);
  103. const height = availableHeight - topBottomMargin;
  104. return {
  105. local: {
  106. height,
  107. width: Math.floor(interfaceConfig.LOCAL_THUMBNAIL_RATIO * height)
  108. },
  109. remote: {
  110. height,
  111. width: Math.floor(interfaceConfig.REMOTE_THUMBNAIL_RATIO * height)
  112. }
  113. };
  114. }
  115. /**
  116. * Calculates the size for thumbnails when in tile view layout.
  117. *
  118. * @param {Object} dimensions - The desired dimensions of the tile view grid.
  119. * @returns {{height, width}}
  120. */
  121. export function calculateThumbnailSizeForTileView({
  122. columns,
  123. visibleRows,
  124. clientWidth,
  125. clientHeight
  126. }: Object) {
  127. const aspectRatio = clientWidth < ASPECT_RATIO_BREAKPOINT ? SQUARE_TILE_ASPECT_RATIO : TILE_ASPECT_RATIO;
  128. const viewWidth = clientWidth - TILE_VIEW_SIDE_MARGINS;
  129. const viewHeight = clientHeight - TILE_VIEW_SIDE_MARGINS;
  130. const initialWidth = viewWidth / columns;
  131. const aspectRatioHeight = initialWidth / aspectRatio;
  132. const height = Math.floor(Math.min(aspectRatioHeight, viewHeight / visibleRows));
  133. const width = Math.floor(aspectRatio * height);
  134. return {
  135. height,
  136. width
  137. };
  138. }
  139. /**
  140. * Returns the width of the visible area (doesn't include the left margin/padding) of the the vertical filmstrip.
  141. *
  142. * @returns {number} - The width of the vertical filmstrip.
  143. */
  144. export function getVerticalFilmstripVisibleAreaWidth() {
  145. // Adding 11px for the 2px right margin, 2px borders on the left and right and 5px right padding.
  146. // Also adding 7px for the scrollbar. Note that we are not counting the left margins and paddings because this
  147. // function is used for calculating the available space and they are invisible.
  148. // TODO: Check if we can remove the left margins and paddings from the CSS.
  149. // FIXME: This function is used to calculate the size of the large video, etherpad or shared video. Once everything
  150. // is reactified this calculation will need to move to the corresponding components.
  151. const filmstripMaxWidth = (interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120) + 18;
  152. return Math.min(filmstripMaxWidth, window.innerWidth);
  153. }