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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 conference = state['features/base/conference'];
  65. const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
  66. const localParticipant = getLocalParticipant(state);
  67. // The settings sections to display.
  68. const showModeratorSettings
  69. = configuredTabs.includes('moderator')
  70. && localParticipant.role === PARTICIPANT_ROLE.MODERATOR;
  71. return {
  72. currentLanguage: language,
  73. followMeEnabled: Boolean(conference.followMeEnabled),
  74. languages: LANGUAGES,
  75. showLanguageSettings: configuredTabs.includes('language'),
  76. showModeratorSettings,
  77. startAudioMuted: Boolean(conference.startAudioMutedPolicy),
  78. startVideoMuted: Boolean(conference.startVideoMutedPolicy)
  79. };
  80. }
  81. /**
  82. * Returns the properties for the "Profile" tab from settings dialog from Redux
  83. * state.
  84. *
  85. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  86. * {@code getState} function to be used to retrieve the state.
  87. * @returns {Object} - The properties for the "Profile" tab from settings
  88. * dialog.
  89. */
  90. export function getProfileTabProps(stateful: Object | Function) {
  91. const state = toState(stateful);
  92. const conference = state['features/base/conference'];
  93. const localParticipant = getLocalParticipant(state);
  94. return {
  95. authEnabled: conference.authEnabled,
  96. authLogin: conference.authLogin,
  97. displayName: localParticipant.name,
  98. email: localParticipant.email
  99. };
  100. }