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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 enabledNotifications = getNotificationsMap(stateful);
  103. const stageFilmstripEnabled = isStageFilmstripEnabled(state);
  104. return {
  105. currentFramerate: framerate,
  106. desktopShareFramerates: SS_SUPPORTED_FRAMERATES,
  107. enabledNotifications,
  108. showNotificationsSettings: Object.keys(enabledNotifications).length > 0,
  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. * @returns {Object} - The properties for the "Sounds" tab from settings
  203. * dialog.
  204. */
  205. export function getSoundsTabProps(stateful: IStateful) {
  206. const state = toState(stateful);
  207. const {
  208. soundsIncomingMessage,
  209. soundsParticipantJoined,
  210. soundsParticipantKnocking,
  211. soundsParticipantLeft,
  212. soundsTalkWhileMuted,
  213. soundsReactions
  214. } = state['features/base/settings'];
  215. const enableReactions = isReactionsEnabled(state);
  216. const moderatorMutedSoundsReactions = state['features/base/conference'].startReactionsMuted ?? false;
  217. return {
  218. disabledSounds: state['features/base/config'].disabledSounds || [],
  219. soundsIncomingMessage,
  220. soundsParticipantJoined,
  221. soundsParticipantKnocking,
  222. soundsParticipantLeft,
  223. soundsTalkWhileMuted,
  224. soundsReactions,
  225. enableReactions,
  226. moderatorMutedSoundsReactions
  227. };
  228. }
  229. /**
  230. * Returns the visibility state of the audio settings.
  231. *
  232. * @param {Object} state - The state of the application.
  233. * @returns {boolean}
  234. */
  235. export function getAudioSettingsVisibility(state: IReduxState) {
  236. return state['features/settings'].audioSettingsVisible;
  237. }
  238. /**
  239. * Returns the visibility state of the video settings.
  240. *
  241. * @param {Object} state - The state of the application.
  242. * @returns {boolean}
  243. */
  244. export function getVideoSettingsVisibility(state: IReduxState) {
  245. return state['features/settings'].videoSettingsVisible;
  246. }