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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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[1] || !urlComponents[1].startsWith('http')) {
  32. url = `https://${urlComponents[2]}`;
  33. }
  34. const parsedURI = parseStandardURIString(url);
  35. if (!parsedURI.host) {
  36. return null;
  37. }
  38. return parsedURI.toString();
  39. }
  40. return url;
  41. /* eslint-enable no-param-reassign */
  42. }
  43. /**
  44. * Used for web. Returns whether or not only Device Selection is configured to
  45. * display as a setting.
  46. *
  47. * @returns {boolean}
  48. */
  49. export function shouldShowOnlyDeviceSelection() {
  50. return interfaceConfig.SETTINGS_SECTIONS.length === 1
  51. && isSettingEnabled('devices');
  52. }
  53. /**
  54. * Returns the properties for the "More" tab from settings dialog from Redux
  55. * state.
  56. *
  57. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  58. * {@code getState} function to be used to retrieve the state.
  59. * @returns {Object} - The properties for the "More" tab from settings dialog.
  60. */
  61. export function getMoreTabProps(stateful: Object | Function) {
  62. const state = toState(stateful);
  63. const language = i18next.language || DEFAULT_LANGUAGE;
  64. const {
  65. conference,
  66. followMeEnabled,
  67. startAudioMutedPolicy,
  68. startVideoMutedPolicy
  69. } = state['features/base/conference'];
  70. const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
  71. const localParticipant = getLocalParticipant(state);
  72. // The settings sections to display.
  73. const showModeratorSettings = Boolean(
  74. conference
  75. && configuredTabs.includes('moderator')
  76. && localParticipant.role === PARTICIPANT_ROLE.MODERATOR);
  77. return {
  78. currentLanguage: language,
  79. followMeEnabled: Boolean(conference && followMeEnabled),
  80. languages: LANGUAGES,
  81. showLanguageSettings: configuredTabs.includes('language'),
  82. showModeratorSettings,
  83. startAudioMuted: Boolean(conference && startAudioMutedPolicy),
  84. startVideoMuted: Boolean(conference && startVideoMutedPolicy)
  85. };
  86. }
  87. /**
  88. * Returns the properties for the "Profile" tab from settings dialog from Redux
  89. * state.
  90. *
  91. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  92. * {@code getState} function to be used to retrieve the state.
  93. * @returns {Object} - The properties for the "Profile" tab from settings
  94. * dialog.
  95. */
  96. export function getProfileTabProps(stateful: Object | Function) {
  97. const state = toState(stateful);
  98. const {
  99. authEnabled,
  100. authLogin,
  101. conference
  102. } = state['features/base/conference'];
  103. const localParticipant = getLocalParticipant(state);
  104. return {
  105. authEnabled: Boolean(conference && authEnabled),
  106. authLogin: Boolean(conference && authLogin),
  107. displayName: localParticipant.name,
  108. email: localParticipant.email
  109. };
  110. }