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

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