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.native.ts 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. import { IReduxState } from '../app/types';
  2. import { IStateful } from '../base/app/types';
  3. import { FILMSTRIP_ENABLED } from '../base/flags/constants';
  4. import { getFeatureFlag } from '../base/flags/functions';
  5. import {
  6. getLocalParticipant,
  7. getParticipantCountWithFake,
  8. getPinnedParticipant
  9. } from '../base/participants/functions';
  10. import Platform from '../base/react/Platform.native';
  11. import { toState } from '../base/redux/functions';
  12. import { ASPECT_RATIO_NARROW } from '../base/responsive-ui/constants';
  13. import { getHideSelfView } from '../base/settings/functions.any';
  14. import conferenceStyles from '../conference/components/native/styles';
  15. import { shouldDisplayTileView } from '../video-layout/functions.native';
  16. import styles from './components/native/styles';
  17. export * from './functions.any';
  18. /**
  19. * Returns true if the filmstrip on mobile is visible, false otherwise.
  20. *
  21. * NOTE: Filmstrip on mobile behaves differently to web, and is only visible
  22. * when there are at least 2 participants.
  23. *
  24. * @param {Object | Function} stateful - The Object or Function that can be
  25. * resolved to a Redux state object with the toState function.
  26. * @returns {boolean}
  27. */
  28. export function isFilmstripVisible(stateful: IStateful) {
  29. const state = toState(stateful);
  30. const enabled = getFeatureFlag(state, FILMSTRIP_ENABLED, true);
  31. if (!enabled) {
  32. return false;
  33. }
  34. return getParticipantCountWithFake(state) > 1;
  35. }
  36. /**
  37. * Determines whether the remote video thumbnails should be displayed/visible in
  38. * the filmstrip.
  39. *
  40. * @param {Object} state - The full redux state.
  41. * @returns {boolean} - If remote video thumbnails should be displayed/visible
  42. * in the filmstrip, then {@code true}; otherwise, {@code false}.
  43. */
  44. export function shouldRemoteVideosBeVisible(state: IReduxState) {
  45. if (state['features/invite'].calleeInfoVisible) {
  46. return false;
  47. }
  48. // Include fake participants to derive how many thumbnails are displayed,
  49. // as it is assumed all participants, including fake, will be displayed
  50. // in the filmstrip.
  51. const participantCount = getParticipantCountWithFake(state);
  52. const pinnedParticipant = getPinnedParticipant(state);
  53. const { disable1On1Mode } = state['features/base/config'];
  54. return Boolean(
  55. participantCount > 2
  56. // Always show the filmstrip when there is another participant to
  57. // show and the local video is pinned. Note we are not taking the
  58. // toolbar visibility into account here (unlike web) because
  59. // showing / hiding views in quick succession on mobile is taxing.
  60. || (participantCount > 1 && pinnedParticipant?.local)
  61. || disable1On1Mode);
  62. }
  63. /**
  64. * Not implemented on mobile.
  65. *
  66. * @param {any} _state - Used on web.
  67. * @returns {Array<string>}
  68. */
  69. export function getActiveParticipantsIds(_state: any) {
  70. return [];
  71. }
  72. /**
  73. * Not implemented on mobile.
  74. *
  75. * @param {any} _state - Redux state.
  76. * @returns {Array<Object>}
  77. */
  78. export function getPinnedActiveParticipants(_state: any) {
  79. return [];
  80. }
  81. /**
  82. * Returns the number of participants displayed in tile view.
  83. *
  84. * @param {Object | Function} stateful - The Object or Function that can be
  85. * resolved to a Redux state object with the toState function.
  86. * @returns {number} - The number of participants displayed in tile view.
  87. */
  88. export function getTileViewParticipantCount(stateful: IStateful) {
  89. const state = toState(stateful);
  90. const disableSelfView = getHideSelfView(state);
  91. const localParticipant = getLocalParticipant(state);
  92. const participantCount = getParticipantCountWithFake(state) - (disableSelfView && localParticipant ? 1 : 0);
  93. return participantCount;
  94. }
  95. /**
  96. * Returns how many columns should be displayed for tile view.
  97. *
  98. * @param {Object | Function} stateful - The Object or Function that can be
  99. * resolved to a Redux state object with the toState function.
  100. * @returns {number} - The number of columns to be rendered in tile view.
  101. * @private
  102. */
  103. export function getColumnCount(stateful: IStateful) {
  104. const state = toState(stateful);
  105. const participantCount = getTileViewParticipantCount(state);
  106. const { aspectRatio } = state['features/base/responsive-ui'];
  107. // For narrow view, tiles should stack on top of each other for a lonely
  108. // call and a 1:1 call. Otherwise tiles should be grouped into rows of
  109. // two.
  110. if (aspectRatio === ASPECT_RATIO_NARROW) {
  111. return participantCount >= 3 ? 2 : 1;
  112. }
  113. if (participantCount === 4) {
  114. // In wide view, a four person call should display as a 2x2 grid.
  115. return 2;
  116. }
  117. return Math.min(participantCount <= 6 ? 3 : 4, participantCount);
  118. }
  119. /**
  120. * Returns true if the filmstrip has a scroll and false otherwise.
  121. *
  122. * @param {Object} state - The redux state.
  123. * @returns {boolean} - True if the scroll is displayed and false otherwise.
  124. */
  125. export function isFilmstripScrollVisible(state: IReduxState) {
  126. if (shouldDisplayTileView(state)) {
  127. return state['features/filmstrip']?.tileViewDimensions?.hasScroll;
  128. }
  129. const { aspectRatio, clientWidth, clientHeight, safeAreaInsets = {} } = state['features/base/responsive-ui'];
  130. const isNarrowAspectRatio = aspectRatio === ASPECT_RATIO_NARROW;
  131. const disableSelfView = getHideSelfView(state);
  132. const localParticipant = Boolean(getLocalParticipant(state));
  133. const localParticipantVisible = localParticipant && !disableSelfView;
  134. const participantCount
  135. = getParticipantCountWithFake(state)
  136. - (localParticipant && (shouldDisplayLocalThumbnailSeparately() || disableSelfView) ? 1 : 0);
  137. const { height: thumbnailHeight, width: thumbnailWidth, margin } = styles.thumbnail;
  138. const { height, width } = getFilmstripDimensions({
  139. aspectRatio,
  140. clientWidth,
  141. clientHeight,
  142. insets: safeAreaInsets,
  143. localParticipantVisible
  144. });
  145. if (isNarrowAspectRatio) {
  146. return width < (thumbnailWidth + (2 * margin)) * participantCount;
  147. }
  148. return height < (thumbnailHeight + (2 * margin)) * participantCount;
  149. }
  150. /**
  151. * Whether the stage filmstrip is available or not.
  152. *
  153. * @param {any} _state - Used on web.
  154. * @param {any} _count - Used on web.
  155. * @returns {boolean}
  156. */
  157. export function isStageFilmstripAvailable(_state: any, _count?: any) {
  158. return false;
  159. }
  160. /**
  161. * Whether the stage filmstrip is enabled.
  162. *
  163. * @param {any} _state - Used on web.
  164. * @returns {boolean}
  165. */
  166. export function isStageFilmstripEnabled(_state: any) {
  167. return false;
  168. }
  169. /**
  170. * Whether or not the top panel is enabled.
  171. *
  172. * @param {any} _state - Used on web.
  173. * @returns {boolean}
  174. */
  175. export function isTopPanelEnabled(_state: any) {
  176. return false;
  177. }
  178. /**
  179. * Calculates the width and height of the filmstrip based on the screen size and aspect ratio.
  180. *
  181. * @param {Object} options - The screen aspect ratio, width, height and safe are insets.
  182. * @returns {Object} - The width and the height.
  183. */
  184. export function getFilmstripDimensions({
  185. aspectRatio,
  186. clientWidth,
  187. clientHeight,
  188. insets = {},
  189. localParticipantVisible = true
  190. }: {
  191. aspectRatio: Symbol;
  192. clientHeight: number;
  193. clientWidth: number;
  194. insets?: {
  195. bottom?: number;
  196. left?: number;
  197. right?: number;
  198. top?: number;
  199. };
  200. localParticipantVisible?: boolean;
  201. }) {
  202. const { height, width, margin } = styles.thumbnail; // @ts-ignore
  203. const conferenceBorder = conferenceStyles.conference.borderWidth || 0;
  204. const { left = 0, right = 0, top = 0, bottom = 0 } = insets;
  205. if (aspectRatio === ASPECT_RATIO_NARROW) {
  206. return {
  207. height,
  208. width:
  209. (shouldDisplayLocalThumbnailSeparately() && localParticipantVisible
  210. ? clientWidth - width - (margin * 2) : clientWidth)
  211. - left - right - (styles.filmstripNarrow.margin * 2) - (conferenceBorder * 2)
  212. };
  213. }
  214. return {
  215. height:
  216. (shouldDisplayLocalThumbnailSeparately() && localParticipantVisible
  217. ? clientHeight - height - (margin * 2) : clientHeight)
  218. - top - bottom - (conferenceBorder * 2),
  219. width
  220. };
  221. }
  222. /**
  223. * Returns true if the local thumbnail should be displayed separately and false otherwise.
  224. *
  225. * @returns {boolean} - True if the local thumbnail should be displayed separately and false otherwise.
  226. */
  227. export function shouldDisplayLocalThumbnailSeparately() {
  228. // XXX Our current design is to have the local participant separate from
  229. // the remote participants. Unfortunately, Android's Video
  230. // implementation cannot accommodate that because remote participants'
  231. // videos appear on top of the local participant's video at times.
  232. // That's because Android's Video utilizes EGL and EGL gives us only two
  233. // practical layers in which we can place our participants' videos:
  234. // layer #0 sits behind the window, creates a hole in the window, and
  235. // there we render the LargeVideo; layer #1 is known as media overlay in
  236. // EGL terms, renders on top of layer #0, and, consequently, is for the
  237. // Filmstrip. With the separate LocalThumbnail, we should have left the
  238. // remote participants' Thumbnails in layer #1 and utilized layer #2 for
  239. // LocalThumbnail. Unfortunately, layer #2 is not practical (that's why
  240. // I said we had two practical layers only) because it renders on top of
  241. // everything which in our case means on top of participant-related
  242. // indicators such as moderator, audio and video muted, etc. For now we
  243. // do not have much of a choice but to continue rendering LocalThumbnail
  244. // as any other remote Thumbnail on Android.
  245. return Platform.OS !== 'android';
  246. }
  247. /**
  248. * Not implemented on mobile.
  249. *
  250. * @param {any} _state - Used on web.
  251. * @returns {undefined}
  252. */
  253. export function getScreenshareFilmstripParticipantId(_state: any) {
  254. return undefined;
  255. }