You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.any.ts 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 { parseStandardURIString } from '../base/util/uri';
  14. import { isStageFilmstripEnabled } from '../filmstrip/functions';
  15. import { isFollowMeActive } from '../follow-me/functions';
  16. import { getParticipantsPaneConfig } from '../participants-pane/functions';
  17. import { isReactionsEnabled } from '../reactions/functions.any';
  18. import { SS_DEFAULT_FRAME_RATE, SS_SUPPORTED_FRAMERATES } from './constants';
  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 framerate = state['features/screen-share'].captureFrameRate ?? SS_DEFAULT_FRAME_RATE;
  102. const language = i18next.language || DEFAULT_LANGUAGE;
  103. const configuredTabs: string[] = interfaceConfig.SETTINGS_SECTIONS || [];
  104. const enabledNotifications = getNotificationsMap(stateful);
  105. const stageFilmstripEnabled = isStageFilmstripEnabled(state);
  106. // when self view is controlled by the config we hide the settings
  107. const { disableSelfView, disableSelfViewSettings } = state['features/base/config'];
  108. return {
  109. currentFramerate: framerate,
  110. currentLanguage: language,
  111. desktopShareFramerates: SS_SUPPORTED_FRAMERATES,
  112. disableHideSelfView: disableSelfViewSettings || disableSelfView,
  113. hideSelfView: getHideSelfView(state),
  114. languages: LANGUAGES,
  115. showLanguageSettings: configuredTabs.includes('language'),
  116. enabledNotifications,
  117. showNotificationsSettings: Object.keys(enabledNotifications).length > 0,
  118. showPrejoinPage: !state['features/base/settings'].userSelectedSkipPrejoin,
  119. showPrejoinSettings: state['features/base/config'].prejoinConfig?.enabled,
  120. maxStageParticipants: state['features/base/settings'].maxStageParticipants,
  121. stageFilmstripEnabled
  122. };
  123. }
  124. /**
  125. * Returns the properties for the "More" tab from settings dialog from Redux
  126. * state.
  127. *
  128. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  129. * {@code getState} function to be used to retrieve the state.
  130. * @returns {Object} - The properties for the "More" tab from settings dialog.
  131. */
  132. export function getModeratorTabProps(stateful: IStateful) {
  133. const state = toState(stateful);
  134. const {
  135. conference,
  136. followMeEnabled,
  137. startAudioMutedPolicy,
  138. startVideoMutedPolicy,
  139. startReactionsMuted
  140. } = state['features/base/conference'];
  141. const { disableReactionsModeration } = state['features/base/config'];
  142. const followMeActive = isFollowMeActive(state);
  143. const showModeratorSettings = shouldShowModeratorSettings(state);
  144. // The settings sections to display.
  145. return {
  146. showModeratorSettings: Boolean(conference && showModeratorSettings),
  147. disableReactionsModeration: Boolean(disableReactionsModeration),
  148. followMeActive: Boolean(conference && followMeActive),
  149. followMeEnabled: Boolean(conference && followMeEnabled),
  150. startReactionsMuted: Boolean(conference && startReactionsMuted),
  151. startAudioMuted: Boolean(conference && startAudioMutedPolicy),
  152. startVideoMuted: Boolean(conference && startVideoMutedPolicy)
  153. };
  154. }
  155. /**
  156. * Returns true if moderator tab in settings should be visible/accessible.
  157. *
  158. * @param {(Function|Object)} stateful - The (whole) redux state, or redux's
  159. * {@code getState} function to be used to retrieve the state.
  160. * @returns {boolean} True to indicate that moderator tab should be visible, false otherwise.
  161. */
  162. export function shouldShowModeratorSettings(stateful: IStateful) {
  163. const state = toState(stateful);
  164. const { hideModeratorSettingsTab } = getParticipantsPaneConfig(state);
  165. const hasModeratorRights = Boolean(isSettingEnabled('moderator') && isLocalParticipantModerator(state));
  166. return hasModeratorRights && !hideModeratorSettingsTab;
  167. }
  168. /**
  169. * Returns the properties for the "Profile" tab from settings dialog from Redux
  170. * state.
  171. *
  172. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  173. * {@code getState} function to be used to retrieve the state.
  174. * @returns {Object} - The properties for the "Profile" tab from settings
  175. * dialog.
  176. */
  177. export function getProfileTabProps(stateful: IStateful) {
  178. const state = toState(stateful);
  179. const {
  180. authEnabled,
  181. authLogin,
  182. conference
  183. } = state['features/base/conference'];
  184. const { hideEmailInSettings } = state['features/base/config'];
  185. const localParticipant = getLocalParticipant(state);
  186. return {
  187. authEnabled: Boolean(conference && authEnabled),
  188. authLogin,
  189. displayName: localParticipant?.name,
  190. email: localParticipant?.email,
  191. readOnlyName: isNameReadOnly(state),
  192. hideEmailInSettings
  193. };
  194. }
  195. /**
  196. * Returns the properties for the "Sounds" tab from settings dialog from Redux
  197. * state.
  198. *
  199. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  200. * {@code getState} function to be used to retrieve the state.
  201. * @returns {Object} - The properties for the "Sounds" tab from settings
  202. * dialog.
  203. */
  204. export function getSoundsTabProps(stateful: IStateful) {
  205. const state = toState(stateful);
  206. const {
  207. soundsIncomingMessage,
  208. soundsParticipantJoined,
  209. soundsParticipantKnocking,
  210. soundsParticipantLeft,
  211. soundsTalkWhileMuted,
  212. soundsReactions
  213. } = state['features/base/settings'];
  214. const enableReactions = isReactionsEnabled(state);
  215. const moderatorMutedSoundsReactions = state['features/base/conference'].startReactionsMuted ?? false;
  216. return {
  217. disabledSounds: state['features/base/config'].disabledSounds || [],
  218. soundsIncomingMessage,
  219. soundsParticipantJoined,
  220. soundsParticipantKnocking,
  221. soundsParticipantLeft,
  222. soundsTalkWhileMuted,
  223. soundsReactions,
  224. enableReactions,
  225. moderatorMutedSoundsReactions
  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. }