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

functions.any.js 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { getFeatureFlag, TILE_VIEW_ENABLED } from '../base/flags';
  4. import {
  5. getPinnedParticipant,
  6. getParticipantCount,
  7. pinParticipant
  8. } from '../base/participants';
  9. import { isStageFilmstripAvailable } from '../filmstrip/functions';
  10. import { isVideoPlaying } from '../shared-video/functions';
  11. import { VIDEO_QUALITY_LEVELS } from '../video-quality/constants';
  12. import { LAYOUTS } from './constants';
  13. declare var interfaceConfig: Object;
  14. /**
  15. * A selector for retrieving the current automatic pinning setting.
  16. *
  17. * @private
  18. * @returns {string|undefined} The string "remote-only" is returned if only
  19. * remote screen sharing should be automatically pinned, any other truthy value
  20. * means automatically pin all screen shares. Falsy means do not automatically
  21. * pin any screen shares.
  22. */
  23. export function getAutoPinSetting() {
  24. return typeof interfaceConfig === 'object'
  25. ? interfaceConfig.AUTO_PIN_LATEST_SCREEN_SHARE
  26. : 'remote-only';
  27. }
  28. /**
  29. * Returns the {@code LAYOUTS} constant associated with the layout
  30. * the application should currently be in.
  31. *
  32. * @param {Object} state - The redux state.
  33. * @returns {string}
  34. */
  35. export function getCurrentLayout(state: Object) {
  36. if (shouldDisplayTileView(state)) {
  37. return LAYOUTS.TILE_VIEW;
  38. } else if (interfaceConfig.VERTICAL_FILMSTRIP) {
  39. if (isStageFilmstripAvailable(state, 2)) {
  40. return LAYOUTS.STAGE_FILMSTRIP_VIEW;
  41. }
  42. return LAYOUTS.VERTICAL_FILMSTRIP_VIEW;
  43. }
  44. return LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW;
  45. }
  46. /**
  47. * Selector for determining if the UI layout should be in tile view. Tile view
  48. * is determined by more than just having the tile view setting enabled, as
  49. * one-on-one calls should not be in tile view, as well as etherpad editing.
  50. *
  51. * @param {Object} state - The redux state.
  52. * @returns {boolean} True if tile view should be displayed.
  53. */
  54. export function shouldDisplayTileView(state: Object = {}) {
  55. const participantCount = getParticipantCount(state);
  56. const tileViewEnabledFeatureFlag = getFeatureFlag(state, TILE_VIEW_ENABLED, true);
  57. const { disableTileView } = state['features/base/config'];
  58. if (disableTileView || !tileViewEnabledFeatureFlag) {
  59. return false;
  60. }
  61. const { tileViewEnabled } = state['features/video-layout'];
  62. if (tileViewEnabled !== undefined) {
  63. // If the user explicitly requested a view mode, we
  64. // do that.
  65. return tileViewEnabled;
  66. }
  67. const { iAmRecorder } = state['features/base/config'];
  68. // None tile view mode is easier to calculate (no need for many negations), so we do
  69. // that and negate it only once.
  70. const shouldDisplayNormalMode = Boolean(
  71. // Reasons for normal mode:
  72. // Editing etherpad
  73. state['features/etherpad']?.editing
  74. // We pinned a participant
  75. || getPinnedParticipant(state)
  76. // It's a 1-on-1 meeting
  77. || participantCount < 3
  78. // There is a shared YouTube video in the meeting
  79. || isVideoPlaying(state)
  80. // We want jibri to use stage view by default
  81. || iAmRecorder
  82. );
  83. return !shouldDisplayNormalMode;
  84. }
  85. /**
  86. * Private helper to automatically pin the latest screen share stream or unpin
  87. * if there are no more screen share streams.
  88. *
  89. * @param {Array<string>} screenShares - Array containing the list of all the screen sharing endpoints
  90. * before the update was triggered (including the ones that have been removed from redux because of the update).
  91. * @param {Store} store - The redux store.
  92. * @returns {void}
  93. */
  94. export function updateAutoPinnedParticipant(
  95. screenShares: Array<string>, { dispatch, getState }: { dispatch: Dispatch<any>, getState: Function }) {
  96. const state = getState();
  97. const remoteScreenShares = state['features/video-layout'].remoteScreenShares;
  98. const pinned = getPinnedParticipant(getState);
  99. // if the pinned participant is shared video or some other fake participant we want to skip auto-pinning
  100. if (pinned?.isFakeParticipant) {
  101. return;
  102. }
  103. // Unpin the screen share when the screen sharing participant leaves. Switch to tile view if no other
  104. // participant was pinned before screen share was auto-pinned, pin the previously pinned participant otherwise.
  105. if (!remoteScreenShares?.length) {
  106. let participantId = null;
  107. if (pinned && !screenShares.find(share => share === pinned.id)) {
  108. participantId = pinned.id;
  109. }
  110. dispatch(pinParticipant(participantId));
  111. return;
  112. }
  113. const latestScreenShareParticipantId = remoteScreenShares[remoteScreenShares.length - 1];
  114. if (latestScreenShareParticipantId) {
  115. dispatch(pinParticipant(latestScreenShareParticipantId));
  116. }
  117. }
  118. /**
  119. * Selector for whether we are currently in tile view.
  120. *
  121. * @param {Object} state - The redux state.
  122. * @returns {boolean}
  123. */
  124. export function isLayoutTileView(state: Object) {
  125. return getCurrentLayout(state) === LAYOUTS.TILE_VIEW;
  126. }
  127. /**
  128. * Gets the video quality for the given height.
  129. *
  130. * @param {number|undefined} height - Height of the video container.
  131. * @returns {number}
  132. */
  133. function getVideoQualityForHeight(height: number) {
  134. if (!height) {
  135. return VIDEO_QUALITY_LEVELS.LOW;
  136. }
  137. const levels = Object.values(VIDEO_QUALITY_LEVELS)
  138. .map(Number)
  139. .sort((a, b) => a - b);
  140. for (const level of levels) {
  141. if (height <= level) {
  142. return level;
  143. }
  144. }
  145. return VIDEO_QUALITY_LEVELS.ULTRA;
  146. }
  147. /**
  148. * Gets the video quality level for the resizable filmstrip thumbnail height.
  149. *
  150. * @param {Object} state - Redux state.
  151. * @returns {number}
  152. */
  153. export function getVideoQualityForResizableFilmstripThumbnails(state) {
  154. const height = state['features/filmstrip'].verticalViewDimensions?.gridView?.thumbnailSize?.height;
  155. return getVideoQualityForHeight(height);
  156. }
  157. /**
  158. * Gets the video quality for the large video.
  159. *
  160. * @returns {number}
  161. */
  162. export function getVideoQualityForLargeVideo() {
  163. const wrapper = document.querySelector('#largeVideoWrapper');
  164. return getVideoQualityForHeight(wrapper.clientHeight);
  165. }
  166. /**
  167. * Gets the video quality level for the thumbnails in the stage filmstrip.
  168. *
  169. * @param {Object} state - Redux state.
  170. * @returns {number}
  171. */
  172. export function getVideoQualityForStageThumbnails(state) {
  173. const height = state['features/filmstrip'].stageFilmstripDimensions?.thumbnailSize?.height;
  174. return getVideoQualityForHeight(height);
  175. }