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 7.8KB

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