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.

actions.ts 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import { batch } from 'react-redux';
  2. // @ts-expect-error
  3. import keyboardShortcut from '../../../modules/keyboardshortcut/keyboardshortcut';
  4. import { IStore } from '../app/types';
  5. import {
  6. setFollowMe,
  7. setStartMutedPolicy,
  8. setStartReactionsMuted
  9. } from '../base/conference/actions';
  10. import { openDialog } from '../base/dialog/actions';
  11. import i18next from '../base/i18n/i18next';
  12. import { updateSettings } from '../base/settings/actions';
  13. import { toggleBackgroundEffect } from '../virtual-background/actions';
  14. import virtualBackgroundLogger from '../virtual-background/logger';
  15. import {
  16. SET_AUDIO_SETTINGS_VISIBILITY,
  17. SET_VIDEO_SETTINGS_VISIBILITY
  18. } from './actionTypes';
  19. // eslint-disable-next-line lines-around-comment
  20. // @ts-ignore
  21. import { LogoutDialog, SettingsDialog } from './components';
  22. import {
  23. getModeratorTabProps,
  24. getMoreTabProps,
  25. getNotificationsTabProps,
  26. getProfileTabProps,
  27. getShortcutsTabProps,
  28. getVirtualBackgroundTabProps
  29. } from './functions';
  30. /**
  31. * Opens {@code LogoutDialog}.
  32. *
  33. * @param {Function} onLogout - The event in {@code LogoutDialog} that should be
  34. * enabled on click.
  35. * @returns {Function}
  36. */
  37. export function openLogoutDialog(onLogout: Function) {
  38. return openDialog(LogoutDialog, { onLogout });
  39. }
  40. /**
  41. * Opens {@code SettingsDialog}.
  42. *
  43. * @param {string} defaultTab - The tab in {@code SettingsDialog} that should be
  44. * displayed initially.
  45. * @param {boolean} isDisplayedOnWelcomePage - Indicates whether the device selection dialog is displayed on the
  46. * welcome page or not.
  47. * @returns {Function}
  48. */
  49. export function openSettingsDialog(defaultTab: string, isDisplayedOnWelcomePage?: boolean) {
  50. return openDialog(SettingsDialog, {
  51. defaultTab,
  52. isDisplayedOnWelcomePage
  53. });
  54. }
  55. /**
  56. * Sets the visibility of the audio settings.
  57. *
  58. * @param {boolean} value - The new value.
  59. * @returns {Function}
  60. */
  61. function setAudioSettingsVisibility(value: boolean) {
  62. return {
  63. type: SET_AUDIO_SETTINGS_VISIBILITY,
  64. value
  65. };
  66. }
  67. /**
  68. * Sets the visibility of the video settings.
  69. *
  70. * @param {boolean} value - The new value.
  71. * @returns {Function}
  72. */
  73. function setVideoSettingsVisibility(value: boolean) {
  74. return {
  75. type: SET_VIDEO_SETTINGS_VISIBILITY,
  76. value
  77. };
  78. }
  79. /**
  80. * Submits the settings from the "More" tab of the settings dialog.
  81. *
  82. * @param {Object} newState - The new settings.
  83. * @returns {Function}
  84. */
  85. export function submitMoreTab(newState: any) {
  86. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  87. const currentState = getMoreTabProps(getState());
  88. const showPrejoinPage = newState.showPrejoinPage;
  89. if (showPrejoinPage !== currentState.showPrejoinPage) {
  90. dispatch(updateSettings({
  91. userSelectedSkipPrejoin: !showPrejoinPage
  92. }));
  93. }
  94. if (newState.maxStageParticipants !== currentState.maxStageParticipants) {
  95. dispatch(updateSettings({ maxStageParticipants: Number(newState.maxStageParticipants) }));
  96. }
  97. };
  98. }
  99. /**
  100. * Submits the settings from the "Moderator" tab of the settings dialog.
  101. *
  102. * @param {Object} newState - The new settings.
  103. * @returns {Function}
  104. */
  105. export function submitModeratorTab(newState: any) {
  106. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  107. const currentState = getModeratorTabProps(getState());
  108. if (newState.followMeEnabled !== currentState.followMeEnabled) {
  109. dispatch(setFollowMe(newState.followMeEnabled));
  110. }
  111. if (newState.startReactionsMuted !== currentState.startReactionsMuted) {
  112. batch(() => {
  113. // updating settings we want to update and backend (notify the rest of the participants)
  114. dispatch(setStartReactionsMuted(newState.startReactionsMuted, true));
  115. dispatch(updateSettings({ soundsReactions: !newState.startReactionsMuted }));
  116. });
  117. }
  118. if (newState.startAudioMuted !== currentState.startAudioMuted
  119. || newState.startVideoMuted !== currentState.startVideoMuted) {
  120. dispatch(setStartMutedPolicy(
  121. newState.startAudioMuted, newState.startVideoMuted));
  122. }
  123. };
  124. }
  125. /**
  126. * Submits the settings from the "Profile" tab of the settings dialog.
  127. *
  128. * @param {Object} newState - The new settings.
  129. * @returns {Function}
  130. */
  131. export function submitProfileTab(newState: any) {
  132. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  133. const currentState = getProfileTabProps(getState());
  134. if (newState.displayName !== currentState.displayName) {
  135. APP.conference.changeLocalDisplayName(newState.displayName);
  136. }
  137. if (newState.email !== currentState.email) {
  138. APP.conference.changeLocalEmail(newState.email);
  139. }
  140. if (newState.hideSelfView !== currentState.hideSelfView) {
  141. dispatch(updateSettings({ disableSelfView: newState.hideSelfView }));
  142. }
  143. if (newState.currentLanguage !== currentState.currentLanguage) {
  144. i18next.changeLanguage(newState.currentLanguage);
  145. }
  146. };
  147. }
  148. /**
  149. * Submits the settings from the "Sounds" tab of the settings dialog.
  150. *
  151. * @param {Object} newState - The new settings.
  152. * @returns {Function}
  153. */
  154. export function submitNotificationsTab(newState: any) {
  155. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  156. const currentState = getNotificationsTabProps(getState());
  157. const shouldNotUpdateReactionSounds = getModeratorTabProps(getState()).startReactionsMuted;
  158. const shouldUpdate = (newState.soundsIncomingMessage !== currentState.soundsIncomingMessage)
  159. || (newState.soundsParticipantJoined !== currentState.soundsParticipantJoined)
  160. || (newState.soundsParticipantKnocking !== currentState.soundsParticipantKnocking)
  161. || (newState.soundsParticipantLeft !== currentState.soundsParticipantLeft)
  162. || (newState.soundsTalkWhileMuted !== currentState.soundsTalkWhileMuted)
  163. || (newState.soundsReactions !== currentState.soundsReactions);
  164. if (shouldUpdate) {
  165. const settingsToUpdate = {
  166. soundsIncomingMessage: newState.soundsIncomingMessage,
  167. soundsParticipantJoined: newState.soundsParticipantJoined,
  168. soundsParticipantKnocking: newState.soundsParticipantKnocking,
  169. soundsParticipantLeft: newState.soundsParticipantLeft,
  170. soundsTalkWhileMuted: newState.soundsTalkWhileMuted,
  171. soundsReactions: newState.soundsReactions
  172. };
  173. if (shouldNotUpdateReactionSounds) {
  174. delete settingsToUpdate.soundsReactions;
  175. }
  176. dispatch(updateSettings(settingsToUpdate));
  177. }
  178. const enabledNotifications = newState.enabledNotifications;
  179. if (enabledNotifications !== currentState.enabledNotifications) {
  180. dispatch(updateSettings({
  181. userSelectedNotifications: {
  182. ...getState()['features/base/settings'].userSelectedNotifications,
  183. ...enabledNotifications
  184. }
  185. }));
  186. }
  187. };
  188. }
  189. /**
  190. * Toggles the visibility of the audio settings.
  191. *
  192. * @returns {void}
  193. */
  194. export function toggleAudioSettings() {
  195. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  196. const value = getState()['features/settings'].audioSettingsVisible;
  197. dispatch(setAudioSettingsVisibility(!value));
  198. };
  199. }
  200. /**
  201. * Toggles the visibility of the video settings.
  202. *
  203. * @returns {void}
  204. */
  205. export function toggleVideoSettings() {
  206. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  207. const value = getState()['features/settings'].videoSettingsVisible;
  208. dispatch(setVideoSettingsVisibility(!value));
  209. };
  210. }
  211. /**
  212. * Submits the settings from the "Shortcuts" tab of the settings dialog.
  213. *
  214. * @param {Object} newState - The new settings.
  215. * @returns {Function}
  216. */
  217. export function submitShortcutsTab(newState: any) {
  218. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  219. const currentState = getShortcutsTabProps(getState());
  220. if (newState.keyboardShortcutsEnabled !== currentState.keyboardShortcutsEnabled) {
  221. keyboardShortcut.enable(newState.keyboardShortcutsEnabled);
  222. }
  223. };
  224. }
  225. /**
  226. * Submits the settings from the "Virtual Background" tab of the settings dialog.
  227. *
  228. * @param {Object} newState - The new settings.
  229. * @param {boolean} isCancel - Whether the change represents a cancel.
  230. * @returns {Function}
  231. */
  232. export function submitVirtualBackgroundTab(newState: any, isCancel = false) {
  233. return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  234. const currentState = getVirtualBackgroundTabProps(getState());
  235. if (newState.options?.selectedThumbnail) {
  236. await dispatch(toggleBackgroundEffect(newState.options, currentState._jitsiTrack));
  237. if (!isCancel) {
  238. // Set x scale to default value.
  239. dispatch(updateSettings({
  240. localFlipX: true
  241. }));
  242. virtualBackgroundLogger.info(`Virtual background type: '${
  243. typeof newState.options.backgroundType === 'undefined'
  244. ? 'none' : newState.options.backgroundType}' applied!`);
  245. }
  246. }
  247. };
  248. }