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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. getParticipantCountWithFake
  9. } from '../base/participants';
  10. import { shouldHideSelfView } from '../base/settings/functions.any';
  11. import {
  12. ASPECT_RATIO_BREAKPOINT,
  13. DEFAULT_MAX_COLUMNS,
  14. ABSOLUTE_MAX_COLUMNS,
  15. SINGLE_COLUMN_BREAKPOINT,
  16. TWO_COLUMN_BREAKPOINT
  17. } from '../filmstrip/constants';
  18. import { isVideoPlaying } from '../shared-video/functions';
  19. import { LAYOUTS } from './constants';
  20. declare var interfaceConfig: Object;
  21. /**
  22. * A selector for retrieving the current automatic pinning setting.
  23. *
  24. * @private
  25. * @returns {string|undefined} The string "remote-only" is returned if only
  26. * remote screen sharing should be automatically pinned, any other truthy value
  27. * means automatically pin all screen shares. Falsy means do not automatically
  28. * pin any screen shares.
  29. */
  30. export function getAutoPinSetting() {
  31. return typeof interfaceConfig === 'object'
  32. ? interfaceConfig.AUTO_PIN_LATEST_SCREEN_SHARE
  33. : 'remote-only';
  34. }
  35. /**
  36. * Returns the {@code LAYOUTS} constant associated with the layout
  37. * the application should currently be in.
  38. *
  39. * @param {Object} state - The redux state.
  40. * @returns {string}
  41. */
  42. export function getCurrentLayout(state: Object) {
  43. if (shouldDisplayTileView(state)) {
  44. return LAYOUTS.TILE_VIEW;
  45. } else if (interfaceConfig.VERTICAL_FILMSTRIP) {
  46. return LAYOUTS.VERTICAL_FILMSTRIP_VIEW;
  47. }
  48. return LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW;
  49. }
  50. /**
  51. * Returns how many columns should be displayed in tile view. The number
  52. * returned will be between 1 and 7, inclusive.
  53. *
  54. * @param {Object} state - The redux store state.
  55. * @param {number} width - Custom width to use for calculation.
  56. * @returns {number}
  57. */
  58. export function getMaxColumnCount(state: Object, width: ?number) {
  59. const configuredMax = (typeof interfaceConfig === 'undefined'
  60. ? DEFAULT_MAX_COLUMNS
  61. : interfaceConfig.TILE_VIEW_MAX_COLUMNS) || DEFAULT_MAX_COLUMNS;
  62. const { disableResponsiveTiles } = state['features/base/config'];
  63. if (!disableResponsiveTiles) {
  64. const { clientWidth } = state['features/base/responsive-ui'];
  65. const widthToUse = width || clientWidth;
  66. const participantCount = getParticipantCount(state);
  67. // If there are just two participants in a conference, enforce single-column view for mobile size.
  68. if (participantCount === 2 && widthToUse < ASPECT_RATIO_BREAKPOINT) {
  69. return Math.min(1, Math.max(configuredMax, 1));
  70. }
  71. // Enforce single column view at very small screen widths.
  72. if (widthToUse < SINGLE_COLUMN_BREAKPOINT) {
  73. return Math.min(1, Math.max(configuredMax, 1));
  74. }
  75. // Enforce two column view below breakpoint.
  76. if (widthToUse < TWO_COLUMN_BREAKPOINT) {
  77. return Math.min(2, Math.max(configuredMax, 1));
  78. }
  79. }
  80. return Math.min(Math.max(configuredMax, 1), ABSOLUTE_MAX_COLUMNS);
  81. }
  82. /**
  83. * Returns the cell count dimensions for tile view. Tile view tries to uphold
  84. * equal count of tiles for height and width, until maxColumn is reached in
  85. * which rows will be added but no more columns.
  86. *
  87. * @param {Object} state - The redux store state.
  88. * @param {number} width - Custom width to use for calculation.
  89. * @returns {Object} An object is return with the desired number of columns,
  90. * rows, and visible rows (the rest should overflow) for the tile view layout.
  91. */
  92. export function getTileViewGridDimensions(state: Object, width: ?number) {
  93. const maxColumns = getMaxColumnCount(state, width);
  94. // When in tile view mode, we must discount ourselves (the local participant) because our
  95. // tile is not visible.
  96. const { iAmRecorder } = state['features/base/config'];
  97. const disableSelfView = shouldHideSelfView(state);
  98. const numberOfParticipants = getParticipantCountWithFake(state)
  99. - (iAmRecorder ? 1 : 0)
  100. - (disableSelfView ? 1 : 0);
  101. const isWeb = navigator.product !== 'ReactNative';
  102. // When there are 3 participants in the call we want them to be placed on a single row unless the maxColumn setting
  103. // is lower.
  104. const columnsToMaintainASquare
  105. = isWeb && numberOfParticipants === 3 ? 3 : Math.ceil(Math.sqrt(numberOfParticipants));
  106. const columns = Math.min(columnsToMaintainASquare, maxColumns);
  107. const rows = Math.ceil(numberOfParticipants / columns);
  108. const minVisibleRows = Math.min(maxColumns, rows);
  109. return {
  110. columns,
  111. minVisibleRows,
  112. rows
  113. };
  114. }
  115. /**
  116. * Selector for determining if the UI layout should be in tile view. Tile view
  117. * is determined by more than just having the tile view setting enabled, as
  118. * one-on-one calls should not be in tile view, as well as etherpad editing.
  119. *
  120. * @param {Object} state - The redux state.
  121. * @returns {boolean} True if tile view should be displayed.
  122. */
  123. export function shouldDisplayTileView(state: Object = {}) {
  124. const participantCount = getParticipantCount(state);
  125. const tileViewEnabledFeatureFlag = getFeatureFlag(state, TILE_VIEW_ENABLED, true);
  126. const { disableTileView } = state['features/base/config'];
  127. if (disableTileView || !tileViewEnabledFeatureFlag) {
  128. return false;
  129. }
  130. const { tileViewEnabled } = state['features/video-layout'];
  131. if (tileViewEnabled !== undefined) {
  132. // If the user explicitly requested a view mode, we
  133. // do that.
  134. return tileViewEnabled;
  135. }
  136. const { iAmRecorder } = state['features/base/config'];
  137. // None tile view mode is easier to calculate (no need for many negations), so we do
  138. // that and negate it only once.
  139. const shouldDisplayNormalMode = Boolean(
  140. // Reasons for normal mode:
  141. // Editing etherpad
  142. state['features/etherpad']?.editing
  143. // We pinned a participant
  144. || getPinnedParticipant(state)
  145. // It's a 1-on-1 meeting
  146. || participantCount < 3
  147. // There is a shared YouTube video in the meeting
  148. || isVideoPlaying(state)
  149. // We want jibri to use stage view by default
  150. || iAmRecorder
  151. );
  152. return !shouldDisplayNormalMode;
  153. }
  154. /**
  155. * Private helper to automatically pin the latest screen share stream or unpin
  156. * if there are no more screen share streams.
  157. *
  158. * @param {Array<string>} screenShares - Array containing the list of all the screen sharing endpoints
  159. * before the update was triggered (including the ones that have been removed from redux because of the update).
  160. * @param {Store} store - The redux store.
  161. * @returns {void}
  162. */
  163. export function updateAutoPinnedParticipant(
  164. screenShares: Array<string>, { dispatch, getState }: { dispatch: Dispatch<any>, getState: Function }) {
  165. const state = getState();
  166. const remoteScreenShares = state['features/video-layout'].remoteScreenShares;
  167. const pinned = getPinnedParticipant(getState);
  168. // if the pinned participant is shared video or some other fake participant we want to skip auto-pinning
  169. if (pinned?.isFakeParticipant) {
  170. return;
  171. }
  172. // Unpin the screen share when the screen sharing participant leaves. Switch to tile view if no other
  173. // participant was pinned before screen share was auto-pinned, pin the previously pinned participant otherwise.
  174. if (!remoteScreenShares?.length) {
  175. let participantId = null;
  176. if (pinned && !screenShares.find(share => share === pinned.id)) {
  177. participantId = pinned.id;
  178. }
  179. dispatch(pinParticipant(participantId));
  180. return;
  181. }
  182. const latestScreenShareParticipantId = remoteScreenShares[remoteScreenShares.length - 1];
  183. if (latestScreenShareParticipantId) {
  184. dispatch(pinParticipant(latestScreenShareParticipantId));
  185. }
  186. }
  187. /**
  188. * Selector for whether we are currently in tile view.
  189. *
  190. * @param {Object} state - The redux state.
  191. * @returns {boolean}
  192. */
  193. export function isLayoutTileView(state: Object) {
  194. return getCurrentLayout(state) === LAYOUTS.TILE_VIEW;
  195. }