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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 columnsToMaintainASquare = Math.ceil(Math.sqrt(numberOfParticipants));
  99. const columns = Math.min(columnsToMaintainASquare, maxColumns);
  100. const rows = Math.ceil(numberOfParticipants / columns);
  101. const minVisibleRows = Math.min(maxColumns, rows);
  102. return {
  103. columns,
  104. minVisibleRows,
  105. rows
  106. };
  107. }
  108. /**
  109. * Selector for determining if the UI layout should be in tile view. Tile view
  110. * is determined by more than just having the tile view setting enabled, as
  111. * one-on-one calls should not be in tile view, as well as etherpad editing.
  112. *
  113. * @param {Object} state - The redux state.
  114. * @returns {boolean} True if tile view should be displayed.
  115. */
  116. export function shouldDisplayTileView(state: Object = {}) {
  117. const participantCount = getParticipantCount(state);
  118. const tileViewEnabledFeatureFlag = getFeatureFlag(state, TILE_VIEW_ENABLED, true);
  119. const { disableTileView } = state['features/base/config'];
  120. if (disableTileView || !tileViewEnabledFeatureFlag) {
  121. return false;
  122. }
  123. const { tileViewEnabled } = state['features/video-layout'];
  124. if (tileViewEnabled !== undefined) {
  125. // If the user explicitly requested a view mode, we
  126. // do that.
  127. return tileViewEnabled;
  128. }
  129. const { iAmRecorder } = state['features/base/config'];
  130. // None tile view mode is easier to calculate (no need for many negations), so we do
  131. // that and negate it only once.
  132. const shouldDisplayNormalMode = Boolean(
  133. // Reasons for normal mode:
  134. // Editing etherpad
  135. state['features/etherpad']?.editing
  136. // We pinned a participant
  137. || getPinnedParticipant(state)
  138. // It's a 1-on-1 meeting
  139. || participantCount < 3
  140. // There is a shared YouTube video in the meeting
  141. || isVideoPlaying(state)
  142. // We want jibri to use stage view by default
  143. || iAmRecorder
  144. );
  145. return !shouldDisplayNormalMode;
  146. }
  147. /**
  148. * Private helper to automatically pin the latest screen share stream or unpin
  149. * if there are no more screen share streams.
  150. *
  151. * @param {Array<string>} screenShares - Array containing the list of all the screen sharing endpoints
  152. * before the update was triggered (including the ones that have been removed from redux because of the update).
  153. * @param {Store} store - The redux store.
  154. * @returns {void}
  155. */
  156. export function updateAutoPinnedParticipant(
  157. screenShares: Array<string>, { dispatch, getState }: { dispatch: Dispatch<any>, getState: Function }) {
  158. const state = getState();
  159. const remoteScreenShares = state['features/video-layout'].remoteScreenShares;
  160. const pinned = getPinnedParticipant(getState);
  161. // if the pinned participant is shared video or some other fake participant we want to skip auto-pinning
  162. if (pinned?.isFakeParticipant) {
  163. return;
  164. }
  165. // Unpin the screen share when the screen sharing participant leaves. Switch to tile view if no other
  166. // participant was pinned before screen share was auto-pinned, pin the previously pinned participant otherwise.
  167. if (!remoteScreenShares?.length) {
  168. let participantId = null;
  169. if (pinned && !screenShares.find(share => share === pinned.id)) {
  170. participantId = pinned.id;
  171. }
  172. dispatch(pinParticipant(participantId));
  173. return;
  174. }
  175. const latestScreenShareParticipantId = remoteScreenShares[remoteScreenShares.length - 1];
  176. if (latestScreenShareParticipantId) {
  177. dispatch(pinParticipant(latestScreenShareParticipantId));
  178. }
  179. }
  180. /**
  181. * Selector for whether we are currently in tile view.
  182. *
  183. * @param {Object} state - The redux state.
  184. * @returns {boolean}
  185. */
  186. export function isLayoutTileView(state: Object) {
  187. return getCurrentLayout(state) === LAYOUTS.TILE_VIEW;
  188. }