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.js 7.3KB

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