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 8.9KB

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