Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

SettingsDialog.tsx 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { makeStyles } from 'tss-react/mui';
  4. import { IReduxState } from '../../../app/types';
  5. import {
  6. IconBell,
  7. IconCalendar,
  8. IconGear,
  9. IconImage,
  10. IconModerator,
  11. IconShortcuts,
  12. IconUser,
  13. IconVideo,
  14. IconVolumeUp
  15. } from '../../../base/icons/svg';
  16. import DialogWithTabs, { IDialogTab } from '../../../base/ui/components/web/DialogWithTabs';
  17. import { isCalendarEnabled } from '../../../calendar-sync/functions.web';
  18. import { submitAudioDeviceSelectionTab, submitVideoDeviceSelectionTab } from '../../../device-selection/actions.web';
  19. import AudioDevicesSelection from '../../../device-selection/components/AudioDevicesSelection';
  20. import VideoDeviceSelection from '../../../device-selection/components/VideoDeviceSelection';
  21. import {
  22. getAudioDeviceSelectionDialogProps,
  23. getVideoDeviceSelectionDialogProps
  24. } from '../../../device-selection/functions.web';
  25. import { checkBlurSupport } from '../../../virtual-background/functions';
  26. import {
  27. submitModeratorTab,
  28. submitMoreTab,
  29. submitNotificationsTab,
  30. submitProfileTab,
  31. submitShortcutsTab,
  32. submitVirtualBackgroundTab
  33. } from '../../actions';
  34. import { SETTINGS_TABS } from '../../constants';
  35. import {
  36. getModeratorTabProps,
  37. getMoreTabProps,
  38. getNotificationsMap,
  39. getNotificationsTabProps,
  40. getProfileTabProps,
  41. getShortcutsTabProps,
  42. getVirtualBackgroundTabProps
  43. } from '../../functions';
  44. import CalendarTab from './CalendarTab';
  45. import ModeratorTab from './ModeratorTab';
  46. import MoreTab from './MoreTab';
  47. import NotificationsTab from './NotificationsTab';
  48. import ProfileTab from './ProfileTab';
  49. import ShortcutsTab from './ShortcutsTab';
  50. import VirtualBackgroundTab from './VirtualBackgroundTab';
  51. /**
  52. * The type of the React {@code Component} props of
  53. * {@link ConnectedSettingsDialog}.
  54. */
  55. interface IProps {
  56. /**
  57. * Information about the tabs to be rendered.
  58. */
  59. _tabs: IDialogTab<any>[];
  60. /**
  61. * Which settings tab should be initially displayed. If not defined then
  62. * the first tab will be displayed.
  63. */
  64. defaultTab: string;
  65. /**
  66. * Invoked to save changed settings.
  67. */
  68. dispatch: Function;
  69. /**
  70. * Indicates whether the device selection dialog is displayed on the
  71. * welcome page or not.
  72. */
  73. isDisplayedOnWelcomePage: boolean;
  74. }
  75. const useStyles = makeStyles()(() => {
  76. return {
  77. settingsDialog: {
  78. display: 'flex',
  79. width: '100%'
  80. }
  81. };
  82. });
  83. const SettingsDialog = ({ _tabs, defaultTab, dispatch }: IProps) => {
  84. const { classes } = useStyles();
  85. const correctDefaultTab = _tabs.find(tab => tab.name === defaultTab)?.name;
  86. const tabs = _tabs.map(tab => {
  87. return {
  88. ...tab,
  89. className: `settings-pane ${classes.settingsDialog}`,
  90. submit: (...args: any) => tab.submit
  91. && dispatch(tab.submit(...args))
  92. };
  93. });
  94. return (
  95. <DialogWithTabs
  96. className = 'settings-dialog'
  97. defaultTab = { correctDefaultTab }
  98. tabs = { tabs }
  99. titleKey = 'settings.title' />
  100. );
  101. };
  102. /**
  103. * Maps (parts of) the Redux state to the associated props for the
  104. * {@code ConnectedSettingsDialog} component.
  105. *
  106. * @param {Object} state - The Redux state.
  107. * @param {Object} ownProps - The props passed to the component.
  108. * @private
  109. * @returns {{
  110. * tabs: Array<Object>
  111. * }}
  112. */
  113. function _mapStateToProps(state: IReduxState, ownProps: any) {
  114. const { isDisplayedOnWelcomePage } = ownProps;
  115. const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
  116. // The settings sections to display.
  117. const showDeviceSettings = configuredTabs.includes('devices');
  118. const moreTabProps = getMoreTabProps(state);
  119. const moderatorTabProps = getModeratorTabProps(state);
  120. const { showModeratorSettings } = moderatorTabProps;
  121. const showMoreTab = configuredTabs.includes('more');
  122. const showProfileSettings
  123. = configuredTabs.includes('profile') && !state['features/base/config'].disableProfile;
  124. const showCalendarSettings
  125. = configuredTabs.includes('calendar') && isCalendarEnabled(state);
  126. const showSoundsSettings = configuredTabs.includes('sounds');
  127. const enabledNotifications = getNotificationsMap(state);
  128. const showNotificationsSettings = Object.keys(enabledNotifications).length > 0;
  129. const virtualBackgroundSupported = checkBlurSupport();
  130. const tabs: IDialogTab<any>[] = [];
  131. if (showDeviceSettings) {
  132. tabs.push({
  133. name: SETTINGS_TABS.AUDIO,
  134. component: AudioDevicesSelection,
  135. labelKey: 'settings.audio',
  136. props: getAudioDeviceSelectionDialogProps(state, isDisplayedOnWelcomePage),
  137. propsUpdateFunction: (tabState: any, newProps: ReturnType<typeof getAudioDeviceSelectionDialogProps>) => {
  138. // Ensure the device selection tab gets updated when new devices
  139. // are found by taking the new props and only preserving the
  140. // current user selected devices. If this were not done, the
  141. // tab would keep using a copy of the initial props it received,
  142. // leaving the device list to become stale.
  143. return {
  144. ...newProps,
  145. noiseSuppressionEnabled: tabState.noiseSuppressionEnabled,
  146. selectedAudioInputId: tabState.selectedAudioInputId,
  147. selectedAudioOutputId: tabState.selectedAudioOutputId
  148. };
  149. },
  150. submit: (newState: any) => submitAudioDeviceSelectionTab(newState, isDisplayedOnWelcomePage),
  151. icon: IconVolumeUp
  152. });
  153. tabs.push({
  154. name: SETTINGS_TABS.VIDEO,
  155. component: VideoDeviceSelection,
  156. labelKey: 'settings.video',
  157. props: getVideoDeviceSelectionDialogProps(state, isDisplayedOnWelcomePage),
  158. propsUpdateFunction: (tabState: any, newProps: ReturnType<typeof getVideoDeviceSelectionDialogProps>) => {
  159. // Ensure the device selection tab gets updated when new devices
  160. // are found by taking the new props and only preserving the
  161. // current user selected devices. If this were not done, the
  162. // tab would keep using a copy of the initial props it received,
  163. // leaving the device list to become stale.
  164. return {
  165. ...newProps,
  166. currentFramerate: tabState?.currentFramerate,
  167. localFlipX: tabState.localFlipX,
  168. selectedVideoInputId: tabState.selectedVideoInputId
  169. };
  170. },
  171. submit: (newState: any) => submitVideoDeviceSelectionTab(newState, isDisplayedOnWelcomePage),
  172. icon: IconVideo
  173. });
  174. }
  175. if (virtualBackgroundSupported) {
  176. tabs.push({
  177. name: SETTINGS_TABS.VIRTUAL_BACKGROUND,
  178. component: VirtualBackgroundTab,
  179. labelKey: 'virtualBackground.title',
  180. props: getVirtualBackgroundTabProps(state),
  181. submit: (newState: any) => submitVirtualBackgroundTab(newState),
  182. cancel: () => {
  183. const { _virtualBackground } = getVirtualBackgroundTabProps(state);
  184. return submitVirtualBackgroundTab({
  185. options: {
  186. backgroundType: _virtualBackground.backgroundType,
  187. enabled: _virtualBackground.backgroundEffectEnabled,
  188. url: _virtualBackground.virtualSource,
  189. selectedThumbnail: _virtualBackground.selectedThumbnail,
  190. blurValue: _virtualBackground.blurValue
  191. }
  192. }, true);
  193. },
  194. icon: IconImage
  195. });
  196. }
  197. if (showSoundsSettings || showNotificationsSettings) {
  198. tabs.push({
  199. name: SETTINGS_TABS.NOTIFICATIONS,
  200. component: NotificationsTab,
  201. labelKey: 'settings.notifications',
  202. propsUpdateFunction: (tabState: any, newProps: ReturnType<typeof getNotificationsTabProps>) => {
  203. return {
  204. ...newProps,
  205. enabledNotifications: tabState?.enabledNotifications || {},
  206. soundsIncomingMessage: tabState?.soundsIncomingMessage,
  207. soundsParticipantJoined: tabState?.soundsParticipantJoined,
  208. soundsParticipantKnocking: tabState?.soundsParticipantKnocking,
  209. soundsParticipantLeft: tabState?.soundsParticipantLeft,
  210. soundsReactions: tabState?.soundsReactions,
  211. soundsTalkWhileMuted: tabState?.soundsTalkWhileMuted
  212. };
  213. },
  214. props: getNotificationsTabProps(state, showSoundsSettings),
  215. submit: submitNotificationsTab,
  216. icon: IconBell
  217. });
  218. }
  219. if (showModeratorSettings) {
  220. tabs.push({
  221. name: SETTINGS_TABS.MODERATOR,
  222. component: ModeratorTab,
  223. labelKey: 'settings.moderator',
  224. props: moderatorTabProps,
  225. propsUpdateFunction: (tabState: any, newProps: typeof moderatorTabProps) => {
  226. // Updates tab props, keeping users selection
  227. return {
  228. ...newProps,
  229. followMeEnabled: tabState?.followMeEnabled,
  230. startAudioMuted: tabState?.startAudioMuted,
  231. startVideoMuted: tabState?.startVideoMuted,
  232. startReactionsMuted: tabState?.startReactionsMuted
  233. };
  234. },
  235. submit: submitModeratorTab,
  236. icon: IconModerator
  237. });
  238. }
  239. if (showProfileSettings) {
  240. tabs.push({
  241. name: SETTINGS_TABS.PROFILE,
  242. component: ProfileTab,
  243. labelKey: 'profile.title',
  244. props: getProfileTabProps(state),
  245. submit: submitProfileTab,
  246. icon: IconUser
  247. });
  248. }
  249. if (showCalendarSettings) {
  250. tabs.push({
  251. name: SETTINGS_TABS.CALENDAR,
  252. component: CalendarTab,
  253. labelKey: 'settings.calendar.title',
  254. icon: IconCalendar
  255. });
  256. }
  257. tabs.push({
  258. name: SETTINGS_TABS.SHORTCUTS,
  259. component: ShortcutsTab,
  260. labelKey: 'settings.shortcuts',
  261. props: getShortcutsTabProps(state, isDisplayedOnWelcomePage),
  262. propsUpdateFunction: (tabState: any, newProps: ReturnType<typeof getShortcutsTabProps>) => {
  263. // Updates tab props, keeping users selection
  264. return {
  265. ...newProps,
  266. keyboardShortcutsEnabled: tabState?.keyboardShortcutsEnabled
  267. };
  268. },
  269. submit: submitShortcutsTab,
  270. icon: IconShortcuts
  271. });
  272. if (showMoreTab) {
  273. tabs.push({
  274. name: SETTINGS_TABS.MORE,
  275. component: MoreTab,
  276. labelKey: 'settings.more',
  277. props: moreTabProps,
  278. propsUpdateFunction: (tabState: any, newProps: typeof moreTabProps) => {
  279. // Updates tab props, keeping users selection
  280. return {
  281. ...newProps,
  282. currentLanguage: tabState?.currentLanguage,
  283. hideSelfView: tabState?.hideSelfView,
  284. showPrejoinPage: tabState?.showPrejoinPage,
  285. maxStageParticipants: tabState?.maxStageParticipants
  286. };
  287. },
  288. submit: submitMoreTab,
  289. icon: IconGear
  290. });
  291. }
  292. return { _tabs: tabs };
  293. }
  294. export default connect(_mapStateToProps)(SettingsDialog);