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

functions.any.ts 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. import { IReduxState } from '../app/types';
  2. import { IStateful } from '../base/app/types';
  3. import { isNameReadOnly } from '../base/config/functions.any';
  4. import { SERVER_URL_CHANGE_ENABLED } from '../base/flags/constants';
  5. import { getFeatureFlag } from '../base/flags/functions';
  6. import i18next, { DEFAULT_LANGUAGE, LANGUAGES } from '../base/i18n/i18next';
  7. import { getLocalParticipant } from '../base/participants/functions';
  8. import { toState } from '../base/redux/functions';
  9. import { getHideSelfView } from '../base/settings/functions.any';
  10. import { parseStandardURIString } from '../base/util/uri';
  11. import { isStageFilmstripEnabled } from '../filmstrip/functions';
  12. import { isFollowMeActive } from '../follow-me/functions';
  13. import { isReactionsEnabled } from '../reactions/functions.any';
  14. import { iAmVisitor } from '../visitors/functions';
  15. import { shouldShowModeratorSettings } from './functions';
  16. /**
  17. * Returns true if user is allowed to change Server URL.
  18. *
  19. * @param {(Function|Object)} stateful - The (whole) redux state, or redux's
  20. * {@code getState} function to be used to retrieve the state.
  21. * @returns {boolean} True to indicate that user can change Server URL, false otherwise.
  22. */
  23. export function isServerURLChangeEnabled(stateful: IStateful) {
  24. const state = toState(stateful);
  25. return getFeatureFlag(state, SERVER_URL_CHANGE_ENABLED, true);
  26. }
  27. /**
  28. * Normalizes a URL entered by the user.
  29. * FIXME: Consider adding this to base/util/uri.
  30. *
  31. * @param {string} url - The URL to validate.
  32. * @returns {string|null} - The normalized URL, or null if the URL is invalid.
  33. */
  34. export function normalizeUserInputURL(url: string) {
  35. /* eslint-disable no-param-reassign */
  36. if (url) {
  37. url = url.replace(/\s/g, '').toLowerCase();
  38. const urlRegExp = new RegExp('^(\\w+://)?(.+)$');
  39. const urlComponents = urlRegExp.exec(url);
  40. if (urlComponents && !urlComponents[1]?.startsWith('http')) {
  41. url = `https://${urlComponents[2]}`;
  42. }
  43. const parsedURI = parseStandardURIString(url);
  44. if (!parsedURI.host) {
  45. return null;
  46. }
  47. return parsedURI.toString();
  48. }
  49. return url;
  50. /* eslint-enable no-param-reassign */
  51. }
  52. /**
  53. * Returns the notification types and their user selected configuration.
  54. *
  55. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  56. * {@code getState} function to be used to retrieve the state.
  57. * @returns {Object} - The section of notifications to be configured.
  58. */
  59. export function getNotificationsMap(stateful: IStateful): { [key: string]: boolean; } {
  60. const state = toState(stateful);
  61. const { notifications } = state['features/base/config'];
  62. const { userSelectedNotifications } = state['features/base/settings'];
  63. if (!userSelectedNotifications) {
  64. return {};
  65. }
  66. return Object.keys(userSelectedNotifications)
  67. .filter(key => !notifications || notifications.includes(key))
  68. .reduce((notificationsMap, key) => {
  69. return {
  70. ...notificationsMap,
  71. [key]: userSelectedNotifications[key]
  72. };
  73. }, {});
  74. }
  75. /**
  76. * Returns the properties for the "More" tab from settings dialog from Redux
  77. * state.
  78. *
  79. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  80. * {@code getState} function to be used to retrieve the state.
  81. * @returns {Object} - The properties for the "More" tab from settings dialog.
  82. */
  83. export function getMoreTabProps(stateful: IStateful) {
  84. const state = toState(stateful);
  85. const stageFilmstripEnabled = isStageFilmstripEnabled(state);
  86. const language = i18next.language || DEFAULT_LANGUAGE;
  87. const configuredTabs: string[] = interfaceConfig.SETTINGS_SECTIONS || [];
  88. // when self view is controlled by the config we hide the settings
  89. const { disableSelfView, disableSelfViewSettings } = state['features/base/config'];
  90. return {
  91. currentLanguage: language,
  92. disableHideSelfView: disableSelfViewSettings || disableSelfView,
  93. hideSelfView: getHideSelfView(state),
  94. iAmVisitor: iAmVisitor(state),
  95. languages: LANGUAGES,
  96. maxStageParticipants: state['features/base/settings'].maxStageParticipants,
  97. showLanguageSettings: configuredTabs.includes('language'),
  98. showPrejoinPage: !state['features/base/settings'].userSelectedSkipPrejoin,
  99. showPrejoinSettings: state['features/base/config'].prejoinConfig?.enabled,
  100. stageFilmstripEnabled
  101. };
  102. }
  103. /**
  104. * Returns the properties for the "More" tab from settings dialog from Redux
  105. * state.
  106. *
  107. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  108. * {@code getState} function to be used to retrieve the state.
  109. * @returns {Object} - The properties for the "More" tab from settings dialog.
  110. */
  111. export function getModeratorTabProps(stateful: IStateful) {
  112. const state = toState(stateful);
  113. const {
  114. conference,
  115. followMeEnabled,
  116. startAudioMutedPolicy,
  117. startVideoMutedPolicy,
  118. startReactionsMuted
  119. } = state['features/base/conference'];
  120. const { disableReactionsModeration } = state['features/base/config'];
  121. const followMeActive = isFollowMeActive(state);
  122. const showModeratorSettings = shouldShowModeratorSettings(state);
  123. // The settings sections to display.
  124. return {
  125. showModeratorSettings: Boolean(conference && showModeratorSettings),
  126. disableReactionsModeration: Boolean(disableReactionsModeration),
  127. followMeActive: Boolean(conference && followMeActive),
  128. followMeEnabled: Boolean(conference && followMeEnabled),
  129. startReactionsMuted: Boolean(conference && startReactionsMuted),
  130. startAudioMuted: Boolean(conference && startAudioMutedPolicy),
  131. startVideoMuted: Boolean(conference && startVideoMutedPolicy)
  132. };
  133. }
  134. /**
  135. * Returns the properties for the "Profile" tab from settings dialog from Redux
  136. * state.
  137. *
  138. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  139. * {@code getState} function to be used to retrieve the state.
  140. * @returns {Object} - The properties for the "Profile" tab from settings
  141. * dialog.
  142. */
  143. export function getProfileTabProps(stateful: IStateful) {
  144. const state = toState(stateful);
  145. const {
  146. authEnabled,
  147. authLogin,
  148. conference
  149. } = state['features/base/conference'];
  150. const config = state['features/base/config'];
  151. let { hideEmailInSettings } = config;
  152. const localParticipant = getLocalParticipant(state);
  153. if (config.gravatar?.disabled
  154. || (localParticipant?.avatarURL && localParticipant?.avatarURL.length > 0)) {
  155. hideEmailInSettings = true;
  156. }
  157. return {
  158. authEnabled: Boolean(conference && authEnabled),
  159. authLogin,
  160. displayName: localParticipant?.name,
  161. email: localParticipant?.email,
  162. hideEmailInSettings,
  163. id: localParticipant?.id,
  164. readOnlyName: isNameReadOnly(state)
  165. };
  166. }
  167. /**
  168. * Returns the properties for the "Sounds" tab from settings dialog from Redux
  169. * state.
  170. *
  171. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  172. * {@code getState} function to be used to retrieve the state.
  173. * @param {boolean} showSoundsSettings - Whether to show the sound settings or not.
  174. * @returns {Object} - The properties for the "Sounds" tab from settings
  175. * dialog.
  176. */
  177. export function getNotificationsTabProps(stateful: IStateful, showSoundsSettings?: boolean) {
  178. const state = toState(stateful);
  179. const {
  180. soundsIncomingMessage,
  181. soundsParticipantJoined,
  182. soundsParticipantKnocking,
  183. soundsParticipantLeft,
  184. soundsTalkWhileMuted,
  185. soundsReactions
  186. } = state['features/base/settings'];
  187. const enableReactions = isReactionsEnabled(state);
  188. const moderatorMutedSoundsReactions = state['features/base/conference'].startReactionsMuted ?? false;
  189. const enabledNotifications = getNotificationsMap(stateful);
  190. return {
  191. disabledSounds: state['features/base/config'].disabledSounds || [],
  192. enabledNotifications,
  193. showNotificationsSettings: Object.keys(enabledNotifications).length > 0,
  194. soundsIncomingMessage,
  195. soundsParticipantJoined,
  196. soundsParticipantKnocking,
  197. soundsParticipantLeft,
  198. soundsTalkWhileMuted,
  199. soundsReactions,
  200. enableReactions,
  201. moderatorMutedSoundsReactions,
  202. showSoundsSettings
  203. };
  204. }
  205. /**
  206. * Returns the visibility state of the audio settings.
  207. *
  208. * @param {Object} state - The state of the application.
  209. * @returns {boolean}
  210. */
  211. export function getAudioSettingsVisibility(state: IReduxState) {
  212. return state['features/settings'].audioSettingsVisible;
  213. }
  214. /**
  215. * Returns the visibility state of the video settings.
  216. *
  217. * @param {Object} state - The state of the application.
  218. * @returns {boolean}
  219. */
  220. export function getVideoSettingsVisibility(state: IReduxState) {
  221. return state['features/settings'].videoSettingsVisible;
  222. }