Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

functions.any.ts 7.6KB

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