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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /* eslint-disable lines-around-comment */
  2. import { IReduxState } from '../app/types';
  3. import { IStateful } from '../base/app/types';
  4. import { isNameReadOnly } from '../base/config/functions';
  5. import { SERVER_URL_CHANGE_ENABLED } from '../base/flags/constants';
  6. import { getFeatureFlag } from '../base/flags/functions';
  7. import i18next, { DEFAULT_LANGUAGE, LANGUAGES } from '../base/i18n/i18next';
  8. import {
  9. getLocalParticipant,
  10. isLocalParticipantModerator
  11. } from '../base/participants/functions';
  12. import { toState } from '../base/redux/functions';
  13. import { getHideSelfView } from '../base/settings/functions';
  14. import { parseStandardURIString } from '../base/util/uri';
  15. // @ts-ignore
  16. import { isStageFilmstripEnabled } from '../filmstrip/functions';
  17. // @ts-ignore
  18. import { isFollowMeActive } from '../follow-me';
  19. import { getParticipantsPaneConfig } from '../participants-pane/functions';
  20. import { isReactionsEnabled } from '../reactions/functions.any';
  21. import { SS_DEFAULT_FRAME_RATE, SS_SUPPORTED_FRAMERATES } from './constants';
  22. /**
  23. * Used for web. Indicates if the setting section is enabled.
  24. *
  25. * @param {string} settingName - The name of the setting section as defined in
  26. * interface_config.js and SettingsMenu.js.
  27. * @returns {boolean} True to indicate that the given setting section
  28. * is enabled, false otherwise.
  29. */
  30. export function isSettingEnabled(settingName: string) {
  31. return interfaceConfig.SETTINGS_SECTIONS.includes(settingName);
  32. }
  33. /**
  34. * Returns true if user is allowed to change Server URL.
  35. *
  36. * @param {(Function|Object)} stateful - The (whole) redux state, or redux's
  37. * {@code getState} function to be used to retrieve the state.
  38. * @returns {boolean} True to indicate that user can change Server URL, false otherwise.
  39. */
  40. export function isServerURLChangeEnabled(stateful: IStateful) {
  41. const state = toState(stateful);
  42. const flag = getFeatureFlag(state, SERVER_URL_CHANGE_ENABLED, true);
  43. return flag;
  44. }
  45. /**
  46. * Normalizes a URL entered by the user.
  47. * FIXME: Consider adding this to base/util/uri.
  48. *
  49. * @param {string} url - The URL to validate.
  50. * @returns {string|null} - The normalized URL, or null if the URL is invalid.
  51. */
  52. export function normalizeUserInputURL(url: string) {
  53. /* eslint-disable no-param-reassign */
  54. if (url) {
  55. url = url.replace(/\s/g, '').toLowerCase();
  56. const urlRegExp = new RegExp('^(\\w+://)?(.+)$');
  57. const urlComponents = urlRegExp.exec(url);
  58. if (urlComponents && (!urlComponents[1]
  59. || !urlComponents[1].startsWith('http'))) {
  60. url = `https://${urlComponents[2]}`;
  61. }
  62. const parsedURI = parseStandardURIString(url);
  63. if (!parsedURI.host) {
  64. return null;
  65. }
  66. return parsedURI.toString();
  67. }
  68. return url;
  69. /* eslint-enable no-param-reassign */
  70. }
  71. /**
  72. * Returns the notification types and their user selected configuration.
  73. *
  74. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  75. * {@code getState} function to be used to retrieve the state.
  76. * @returns {Object} - The section of notifications to be configured.
  77. */
  78. export function getNotificationsMap(stateful: IStateful) {
  79. const state = toState(stateful);
  80. const { notifications } = state['features/base/config'];
  81. const { userSelectedNotifications } = state['features/base/settings'];
  82. if (!userSelectedNotifications) {
  83. return {};
  84. }
  85. return Object.keys(userSelectedNotifications)
  86. .filter(key => !notifications || notifications.includes(key))
  87. .reduce((notificationsMap, key) => {
  88. return {
  89. ...notificationsMap,
  90. [key]: userSelectedNotifications[key]
  91. };
  92. }, {});
  93. }
  94. /**
  95. * Returns the properties for the "More" tab from settings dialog from Redux
  96. * state.
  97. *
  98. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  99. * {@code getState} function to be used to retrieve the state.
  100. * @returns {Object} - The properties for the "More" tab from settings dialog.
  101. */
  102. export function getMoreTabProps(stateful: IStateful) {
  103. const state = toState(stateful);
  104. const framerate = state['features/screen-share'].captureFrameRate ?? SS_DEFAULT_FRAME_RATE;
  105. const language = i18next.language || DEFAULT_LANGUAGE;
  106. const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
  107. const enabledNotifications = getNotificationsMap(stateful);
  108. const stageFilmstripEnabled = isStageFilmstripEnabled(state);
  109. // when self view is controlled by the config we hide the settings
  110. const { disableSelfView, disableSelfViewSettings } = state['features/base/config'];
  111. return {
  112. currentFramerate: framerate,
  113. currentLanguage: language,
  114. desktopShareFramerates: SS_SUPPORTED_FRAMERATES,
  115. disableHideSelfView: disableSelfViewSettings || disableSelfView,
  116. hideSelfView: getHideSelfView(state),
  117. languages: LANGUAGES,
  118. showLanguageSettings: configuredTabs.includes('language'),
  119. enabledNotifications,
  120. showNotificationsSettings: Object.keys(enabledNotifications).length > 0,
  121. showPrejoinPage: !state['features/base/settings'].userSelectedSkipPrejoin,
  122. showPrejoinSettings: state['features/base/config'].prejoinConfig?.enabled,
  123. maxStageParticipants: state['features/base/settings'].maxStageParticipants,
  124. stageFilmstripEnabled
  125. };
  126. }
  127. /**
  128. * Returns the properties for the "More" tab from settings dialog from Redux
  129. * state.
  130. *
  131. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  132. * {@code getState} function to be used to retrieve the state.
  133. * @returns {Object} - The properties for the "More" tab from settings dialog.
  134. */
  135. export function getModeratorTabProps(stateful: IStateful) {
  136. const state = toState(stateful);
  137. const {
  138. conference,
  139. followMeEnabled,
  140. startAudioMutedPolicy,
  141. startVideoMutedPolicy,
  142. startReactionsMuted
  143. } = state['features/base/conference'];
  144. const { disableReactionsModeration } = state['features/base/config'];
  145. const followMeActive = isFollowMeActive(state);
  146. const showModeratorSettings = shouldShowModeratorSettings(state);
  147. // The settings sections to display.
  148. return {
  149. showModeratorSettings: Boolean(conference && showModeratorSettings),
  150. disableReactionsModeration: Boolean(disableReactionsModeration),
  151. followMeActive: Boolean(conference && followMeActive),
  152. followMeEnabled: Boolean(conference && followMeEnabled),
  153. startReactionsMuted: Boolean(conference && startReactionsMuted),
  154. startAudioMuted: Boolean(conference && startAudioMutedPolicy),
  155. startVideoMuted: Boolean(conference && startVideoMutedPolicy)
  156. };
  157. }
  158. /**
  159. * Returns true if moderator tab in settings should be visible/accessible.
  160. *
  161. * @param {(Function|Object)} stateful - The (whole) redux state, or redux's
  162. * {@code getState} function to be used to retrieve the state.
  163. * @returns {boolean} True to indicate that moderator tab should be visible, false otherwise.
  164. */
  165. export function shouldShowModeratorSettings(stateful: IStateful) {
  166. const state = toState(stateful);
  167. const { hideModeratorSettingsTab } = getParticipantsPaneConfig(state);
  168. const hasModeratorRights = Boolean(isSettingEnabled('moderator') && isLocalParticipantModerator(state));
  169. return hasModeratorRights && !hideModeratorSettingsTab;
  170. }
  171. /**
  172. * Returns the properties for the "Profile" tab from settings dialog from Redux
  173. * state.
  174. *
  175. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  176. * {@code getState} function to be used to retrieve the state.
  177. * @returns {Object} - The properties for the "Profile" tab from settings
  178. * dialog.
  179. */
  180. export function getProfileTabProps(stateful: IStateful) {
  181. const state = toState(stateful);
  182. const {
  183. authEnabled,
  184. authLogin,
  185. conference
  186. } = state['features/base/conference'];
  187. const { hideEmailInSettings } = state['features/base/config'];
  188. const localParticipant = getLocalParticipant(state);
  189. return {
  190. authEnabled: Boolean(conference && authEnabled),
  191. authLogin,
  192. displayName: localParticipant?.name,
  193. email: localParticipant?.email,
  194. readOnlyName: isNameReadOnly(state),
  195. hideEmailInSettings
  196. };
  197. }
  198. /**
  199. * Returns the properties for the "Sounds" tab from settings dialog from Redux
  200. * state.
  201. *
  202. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  203. * {@code getState} function to be used to retrieve the state.
  204. * @returns {Object} - The properties for the "Sounds" tab from settings
  205. * dialog.
  206. */
  207. export function getSoundsTabProps(stateful: IStateful) {
  208. const state = toState(stateful);
  209. const {
  210. soundsIncomingMessage,
  211. soundsParticipantJoined,
  212. soundsParticipantKnocking,
  213. soundsParticipantLeft,
  214. soundsTalkWhileMuted,
  215. soundsReactions
  216. } = state['features/base/settings'];
  217. const enableReactions = isReactionsEnabled(state);
  218. const moderatorMutedSoundsReactions = state['features/base/conference'].startReactionsMuted ?? false;
  219. return {
  220. soundsIncomingMessage,
  221. soundsParticipantJoined,
  222. soundsParticipantKnocking,
  223. soundsParticipantLeft,
  224. soundsTalkWhileMuted,
  225. soundsReactions,
  226. enableReactions,
  227. moderatorMutedSoundsReactions
  228. };
  229. }
  230. /**
  231. * Returns the visibility state of the audio settings.
  232. *
  233. * @param {Object} state - The state of the application.
  234. * @returns {boolean}
  235. */
  236. export function getAudioSettingsVisibility(state: IReduxState) {
  237. return state['features/settings'].audioSettingsVisible;
  238. }
  239. /**
  240. * Returns the visibility state of the video settings.
  241. *
  242. * @param {Object} state - The state of the application.
  243. * @returns {boolean}
  244. */
  245. export function getVideoSettingsVisibility(state: IReduxState) {
  246. return state['features/settings'].videoSettingsVisible;
  247. }