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.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // @flow
  2. import { toState } from '../base/redux';
  3. import { parseStandardURIString } from '../base/util';
  4. import { i18next, DEFAULT_LANGUAGE, LANGUAGES } from '../base/i18n';
  5. import {
  6. getLocalParticipant,
  7. isLocalParticipantModerator
  8. } from '../base/participants';
  9. declare var interfaceConfig: Object;
  10. /**
  11. * Used for web. Indicates if the setting section is enabled.
  12. *
  13. * @param {string} settingName - The name of the setting section as defined in
  14. * interface_config.js and SettingsMenu.js.
  15. * @returns {boolean} True to indicate that the given setting section
  16. * is enabled, false otherwise.
  17. */
  18. export function isSettingEnabled(settingName: string) {
  19. return interfaceConfig.SETTINGS_SECTIONS.includes(settingName);
  20. }
  21. /**
  22. * Normalizes a URL entered by the user.
  23. * FIXME: Consider adding this to base/util/uri.
  24. *
  25. * @param {string} url - The URL to validate.
  26. * @returns {string|null} - The normalized URL, or null if the URL is invalid.
  27. */
  28. export function normalizeUserInputURL(url: string) {
  29. /* eslint-disable no-param-reassign */
  30. if (url) {
  31. url = url.replace(/\s/g, '').toLowerCase();
  32. const urlRegExp = new RegExp('^(\\w+://)?(.+)$');
  33. const urlComponents = urlRegExp.exec(url);
  34. if (urlComponents && (!urlComponents[1]
  35. || !urlComponents[1].startsWith('http'))) {
  36. url = `https://${urlComponents[2]}`;
  37. }
  38. const parsedURI = parseStandardURIString(url);
  39. if (!parsedURI.host) {
  40. return null;
  41. }
  42. return parsedURI.toString();
  43. }
  44. return url;
  45. /* eslint-enable no-param-reassign */
  46. }
  47. /**
  48. * Used for web. Returns whether or not only Device Selection is configured to
  49. * display as a setting.
  50. *
  51. * @returns {boolean}
  52. */
  53. export function shouldShowOnlyDeviceSelection() {
  54. return interfaceConfig.SETTINGS_SECTIONS.length === 1
  55. && isSettingEnabled('devices');
  56. }
  57. /**
  58. * Returns the properties for the "More" tab from settings dialog from Redux
  59. * state.
  60. *
  61. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  62. * {@code getState} function to be used to retrieve the state.
  63. * @returns {Object} - The properties for the "More" tab from settings dialog.
  64. */
  65. export function getMoreTabProps(stateful: Object | Function) {
  66. const state = toState(stateful);
  67. const language = i18next.language || DEFAULT_LANGUAGE;
  68. const {
  69. conference,
  70. followMeEnabled,
  71. startAudioMutedPolicy,
  72. startVideoMutedPolicy
  73. } = state['features/base/conference'];
  74. const followMeActive = Boolean(state['features/follow-me'].moderator);
  75. const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
  76. // The settings sections to display.
  77. const showModeratorSettings = Boolean(
  78. conference
  79. && configuredTabs.includes('moderator')
  80. && isLocalParticipantModerator(state));
  81. return {
  82. currentLanguage: language,
  83. followMeActive: Boolean(conference && followMeActive),
  84. followMeEnabled: Boolean(conference && followMeEnabled),
  85. languages: LANGUAGES,
  86. showLanguageSettings: configuredTabs.includes('language'),
  87. showModeratorSettings,
  88. startAudioMuted: Boolean(conference && startAudioMutedPolicy),
  89. startVideoMuted: Boolean(conference && startVideoMutedPolicy)
  90. };
  91. }
  92. /**
  93. * Returns the properties for the "Profile" tab from settings dialog from Redux
  94. * state.
  95. *
  96. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  97. * {@code getState} function to be used to retrieve the state.
  98. * @returns {Object} - The properties for the "Profile" tab from settings
  99. * dialog.
  100. */
  101. export function getProfileTabProps(stateful: Object | Function) {
  102. const state = toState(stateful);
  103. const {
  104. authEnabled,
  105. authLogin,
  106. conference
  107. } = state['features/base/conference'];
  108. const localParticipant = getLocalParticipant(state);
  109. return {
  110. authEnabled: Boolean(conference && authEnabled),
  111. authLogin,
  112. displayName: localParticipant.name,
  113. email: localParticipant.email
  114. };
  115. }