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 8.1KB

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