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

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