Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

functions.js 8.1KB

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