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

functions.any.ts 10KB

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