您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.js 4.0KB

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