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.4KB

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