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

functions.any.ts 11KB

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