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

functions.any.ts 7.6KB

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