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

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