You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.any.ts 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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, isTileViewModeDisabled } 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 tileViewDisabled = isTileViewModeDisabled(state);
  58. if (tileViewDisabled) {
  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 tileViewEnabledFeatureFlag = getFeatureFlag(state, TILE_VIEW_ENABLED, true);
  68. const { disableTileView } = state['features/base/config'];
  69. if (disableTileView || !tileViewEnabledFeatureFlag) {
  70. return false;
  71. }
  72. const participantCount = getParticipantCount(state);
  73. const { iAmRecorder } = state['features/base/config'];
  74. // None tile view mode is easier to calculate (no need for many negations), so we do
  75. // that and negate it only once.
  76. const shouldDisplayNormalMode = Boolean(
  77. // Reasons for normal mode:
  78. // Editing etherpad
  79. state['features/etherpad']?.editing
  80. // We pinned a participant
  81. || getPinnedParticipant(state)
  82. // It's a 1-on-1 meeting
  83. || participantCount < 3
  84. // There is a shared YouTube video in the meeting
  85. || isVideoPlaying(state)
  86. // We want jibri to use stage view by default
  87. || iAmRecorder
  88. );
  89. return !shouldDisplayNormalMode;
  90. }
  91. /**
  92. * Private helper to automatically pin the latest screen share stream or unpin
  93. * if there are no more screen share streams.
  94. *
  95. * @param {Array<string>} screenShares - Array containing the list of all the screen sharing endpoints
  96. * before the update was triggered (including the ones that have been removed from redux because of the update).
  97. * @param {Store} store - The redux store.
  98. * @returns {void}
  99. */
  100. export function updateAutoPinnedParticipant(
  101. screenShares: Array<string>, { dispatch, getState }: IStore) {
  102. const state = getState();
  103. const remoteScreenShares = state['features/video-layout'].remoteScreenShares;
  104. const pinned = getPinnedParticipant(getState);
  105. // if the pinned participant is shared video or some other fake participant we want to skip auto-pinning
  106. if (pinned?.fakeParticipant && pinned.fakeParticipant !== FakeParticipant.RemoteScreenShare) {
  107. return;
  108. }
  109. // Unpin the screen share when the screen sharing participant leaves. Switch to tile view if no other
  110. // participant was pinned before screen share was auto-pinned, pin the previously pinned participant otherwise.
  111. if (!remoteScreenShares?.length) {
  112. let participantId = null;
  113. if (pinned && !screenShares.find(share => share === pinned.id)) {
  114. participantId = pinned.id;
  115. }
  116. dispatch(pinParticipant(participantId));
  117. return;
  118. }
  119. const latestScreenShareParticipantId = remoteScreenShares[remoteScreenShares.length - 1];
  120. if (latestScreenShareParticipantId) {
  121. dispatch(pinParticipant(latestScreenShareParticipantId));
  122. }
  123. }
  124. /**
  125. * Selector for whether we are currently in tile view.
  126. *
  127. * @param {Object} state - The redux state.
  128. * @returns {boolean}
  129. */
  130. export function isLayoutTileView(state: IReduxState) {
  131. return getCurrentLayout(state) === LAYOUTS.TILE_VIEW;
  132. }
  133. /**
  134. * Returns the video quality for the given height.
  135. *
  136. * @param {number|undefined} height - Height of the video container.
  137. * @returns {number}
  138. */
  139. function getVideoQualityForHeight(height: number) {
  140. if (!height) {
  141. return VIDEO_QUALITY_LEVELS.LOW;
  142. }
  143. const levels = Object.values(VIDEO_QUALITY_LEVELS)
  144. .map(Number)
  145. .sort((a, b) => a - b);
  146. for (const level of levels) {
  147. if (height <= level) {
  148. return level;
  149. }
  150. }
  151. return VIDEO_QUALITY_LEVELS.ULTRA;
  152. }
  153. /**
  154. * Returns the video quality level for the resizable filmstrip thumbnail height.
  155. *
  156. * @param {number} height - The height of the thumbnail.
  157. * @param {Object} state - Redux state.
  158. * @returns {number}
  159. */
  160. export function getVideoQualityForResizableFilmstripThumbnails(height: number, state: IReduxState) {
  161. if (!height) {
  162. return VIDEO_QUALITY_LEVELS.LOW;
  163. }
  164. return getReceiverVideoQualityLevel(height, getMinHeightForQualityLvlMap(state));
  165. }
  166. /**
  167. * Returns the video quality level for the screen sharing filmstrip thumbnail height.
  168. *
  169. * @param {number} height - The height of the thumbnail.
  170. * @param {Object} state - Redux state.
  171. * @returns {number}
  172. */
  173. export function getVideoQualityForScreenSharingFilmstrip(height: number, state: IReduxState) {
  174. if (!height) {
  175. return VIDEO_QUALITY_LEVELS.LOW;
  176. }
  177. return getReceiverVideoQualityLevel(height, getMinHeightForQualityLvlMap(state));
  178. }
  179. /**
  180. * Returns the video quality for the large video.
  181. *
  182. * @param {number} largeVideoHeight - The height of the large video.
  183. * @returns {number} - The video quality for the large video.
  184. */
  185. export function getVideoQualityForLargeVideo(largeVideoHeight: number) {
  186. return getVideoQualityForHeight(largeVideoHeight);
  187. }
  188. /**
  189. * Returns the video quality level for the thumbnails in the stage filmstrip.
  190. *
  191. * @param {number} height - The height of the thumbnails.
  192. * @param {Object} state - Redux state.
  193. * @returns {number}
  194. */
  195. export function getVideoQualityForStageThumbnails(height: number, state: IReduxState) {
  196. if (!height) {
  197. return VIDEO_QUALITY_LEVELS.LOW;
  198. }
  199. return getReceiverVideoQualityLevel(height, getMinHeightForQualityLvlMap(state));
  200. }