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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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, isFollowMeRecorderActive } 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. followMeRecorderEnabled,
  118. startAudioMutedPolicy,
  119. startVideoMutedPolicy,
  120. startReactionsMuted
  121. } = state['features/base/conference'];
  122. const { disableReactionsModeration } = state['features/base/config'];
  123. const followMeActive = isFollowMeActive(state);
  124. const followMeRecorderActive = isFollowMeRecorderActive(state);
  125. const showModeratorSettings = shouldShowModeratorSettings(state);
  126. // The settings sections to display.
  127. return {
  128. showModeratorSettings: Boolean(conference && showModeratorSettings),
  129. disableReactionsModeration: Boolean(disableReactionsModeration),
  130. followMeActive: Boolean(conference && followMeActive),
  131. followMeEnabled: Boolean(conference && followMeEnabled),
  132. followMeRecorderActive: Boolean(conference && followMeRecorderActive),
  133. followMeRecorderEnabled: Boolean(conference && followMeRecorderEnabled),
  134. startReactionsMuted: Boolean(conference && startReactionsMuted),
  135. startAudioMuted: Boolean(conference && startAudioMutedPolicy),
  136. startVideoMuted: Boolean(conference && startVideoMutedPolicy)
  137. };
  138. }
  139. /**
  140. * Returns the properties for the "Profile" tab from settings dialog from Redux
  141. * state.
  142. *
  143. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  144. * {@code getState} function to be used to retrieve the state.
  145. * @returns {Object} - The properties for the "Profile" tab from settings
  146. * dialog.
  147. */
  148. export function getProfileTabProps(stateful: IStateful) {
  149. const state = toState(stateful);
  150. const {
  151. authEnabled,
  152. authLogin,
  153. conference
  154. } = state['features/base/conference'];
  155. const config = state['features/base/config'];
  156. let { hideEmailInSettings } = config;
  157. const localParticipant = getLocalParticipant(state);
  158. if (config.gravatar?.disabled
  159. || (localParticipant?.avatarURL && localParticipant?.avatarURL.length > 0)) {
  160. hideEmailInSettings = true;
  161. }
  162. return {
  163. authEnabled: Boolean(conference && authEnabled),
  164. authLogin,
  165. displayName: localParticipant?.name,
  166. email: localParticipant?.email,
  167. hideEmailInSettings,
  168. id: localParticipant?.id,
  169. readOnlyName: isNameReadOnly(state)
  170. };
  171. }
  172. /**
  173. * Returns the properties for the "Sounds" tab from settings dialog from Redux
  174. * state.
  175. *
  176. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  177. * {@code getState} function to be used to retrieve the state.
  178. * @param {boolean} showSoundsSettings - Whether to show the sound settings or not.
  179. * @returns {Object} - The properties for the "Sounds" tab from settings
  180. * dialog.
  181. */
  182. export function getNotificationsTabProps(stateful: IStateful, showSoundsSettings?: boolean) {
  183. const state = toState(stateful);
  184. const {
  185. soundsIncomingMessage,
  186. soundsParticipantJoined,
  187. soundsParticipantKnocking,
  188. soundsParticipantLeft,
  189. soundsTalkWhileMuted,
  190. soundsReactions
  191. } = state['features/base/settings'];
  192. const enableReactions = isReactionsEnabled(state);
  193. const moderatorMutedSoundsReactions = state['features/base/conference'].startReactionsMuted ?? false;
  194. const enabledNotifications = getNotificationsMap(stateful);
  195. return {
  196. disabledSounds: state['features/base/config'].disabledSounds || [],
  197. enabledNotifications,
  198. showNotificationsSettings: Object.keys(enabledNotifications).length > 0,
  199. soundsIncomingMessage,
  200. soundsParticipantJoined,
  201. soundsParticipantKnocking,
  202. soundsParticipantLeft,
  203. soundsTalkWhileMuted,
  204. soundsReactions,
  205. enableReactions,
  206. moderatorMutedSoundsReactions,
  207. showSoundsSettings
  208. };
  209. }
  210. /**
  211. * Returns the visibility state of the audio settings.
  212. *
  213. * @param {Object} state - The state of the application.
  214. * @returns {boolean}
  215. */
  216. export function getAudioSettingsVisibility(state: IReduxState) {
  217. return state['features/settings'].audioSettingsVisible;
  218. }
  219. /**
  220. * Returns the visibility state of the video settings.
  221. *
  222. * @param {Object} state - The state of the application.
  223. * @returns {boolean}
  224. */
  225. export function getVideoSettingsVisibility(state: IReduxState) {
  226. return state['features/settings'].videoSettingsVisible;
  227. }