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

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