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

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