Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

functions.any.ts 8.9KB

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