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.js 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. // @flow
  2. import { batch } from 'react-redux';
  3. import {
  4. setFollowMe,
  5. setStartMutedPolicy,
  6. setStartReactionsMuted
  7. } from '../base/conference';
  8. import { openDialog } from '../base/dialog';
  9. import { i18next } from '../base/i18n';
  10. import { updateSettings } from '../base/settings';
  11. import { setPrejoinPageVisibility, setSkipPrejoinIsChanging } from '../prejoin/actions';
  12. import { setScreenshareFramerate } from '../screen-share/actions';
  13. import {
  14. SET_AUDIO_SETTINGS_VISIBILITY,
  15. SET_VIDEO_SETTINGS_VISIBILITY
  16. } from './actionTypes';
  17. import { LogoutDialog, SettingsDialog } from './components';
  18. import {
  19. getModeratorTabProps,
  20. getMoreTabProps,
  21. getProfileTabProps,
  22. getSoundsTabProps
  23. } from './functions';
  24. declare var APP: Object;
  25. /**
  26. * Opens {@code LogoutDialog}.
  27. *
  28. * @param {Function} onLogout - The event in {@code LogoutDialog} that should be
  29. * enabled on click.
  30. * @returns {Function}
  31. */
  32. export function openLogoutDialog(onLogout: Function) {
  33. return openDialog(LogoutDialog, { onLogout });
  34. }
  35. /**
  36. * Opens {@code SettingsDialog}.
  37. *
  38. * @param {string} defaultTab - The tab in {@code SettingsDialog} that should be
  39. * displayed initially.
  40. * @returns {Function}
  41. */
  42. export function openSettingsDialog(defaultTab: string) {
  43. return openDialog(SettingsDialog, { defaultTab });
  44. }
  45. /**
  46. * Sets the visibility of the audio settings.
  47. *
  48. * @param {boolean} value - The new value.
  49. * @returns {Function}
  50. */
  51. function setAudioSettingsVisibility(value: boolean) {
  52. return {
  53. type: SET_AUDIO_SETTINGS_VISIBILITY,
  54. value
  55. };
  56. }
  57. /**
  58. * Sets the visibility of the video settings.
  59. *
  60. * @param {boolean} value - The new value.
  61. * @returns {Function}
  62. */
  63. function setVideoSettingsVisibility(value: boolean) {
  64. return {
  65. type: SET_VIDEO_SETTINGS_VISIBILITY,
  66. value
  67. };
  68. }
  69. /**
  70. * Submits the settings from the "More" tab of the settings dialog.
  71. *
  72. * @param {Object} newState - The new settings.
  73. * @returns {Function}
  74. */
  75. export function submitMoreTab(newState: Object): Function {
  76. return (dispatch, getState) => {
  77. const currentState = getMoreTabProps(getState());
  78. const showPrejoinPage = newState.showPrejoinPage;
  79. if (showPrejoinPage !== currentState.showPrejoinPage) {
  80. // The 'showPrejoin' flag starts as 'true' on every new session.
  81. // This prevents displaying the prejoin page when the user re-enables it.
  82. if (showPrejoinPage && getState()['features/prejoin']?.showPrejoin) {
  83. dispatch(setPrejoinPageVisibility(false));
  84. }
  85. batch(() => {
  86. dispatch(setSkipPrejoinIsChanging(true));
  87. dispatch(updateSettings({
  88. userSelectedSkipPrejoin: !showPrejoinPage
  89. }));
  90. });
  91. }
  92. const enabledNotifications = newState.enabledNotifications;
  93. if (enabledNotifications !== currentState.enabledNotifications) {
  94. dispatch(updateSettings({
  95. userSelectedNotifications: {
  96. ...getState()['features/base/settings'].userSelectedNotifications,
  97. ...enabledNotifications
  98. }
  99. }));
  100. }
  101. if (newState.currentLanguage !== currentState.currentLanguage) {
  102. i18next.changeLanguage(newState.currentLanguage);
  103. }
  104. if (newState.currentFramerate !== currentState.currentFramerate) {
  105. const frameRate = parseInt(newState.currentFramerate, 10);
  106. dispatch(setScreenshareFramerate(frameRate));
  107. }
  108. if (newState.hideSelfView !== currentState.hideSelfView) {
  109. dispatch(updateSettings({ disableSelfView: newState.hideSelfView }));
  110. }
  111. };
  112. }
  113. /**
  114. * Submits the settings from the "Moderator" tab of the settings dialog.
  115. *
  116. * @param {Object} newState - The new settings.
  117. * @returns {Function}
  118. */
  119. export function submitModeratorTab(newState: Object): Function {
  120. return (dispatch, getState) => {
  121. const currentState = getModeratorTabProps(getState());
  122. if (newState.followMeEnabled !== currentState.followMeEnabled) {
  123. dispatch(setFollowMe(newState.followMeEnabled));
  124. }
  125. if (newState.startReactionsMuted !== currentState.startReactionsMuted) {
  126. batch(() => {
  127. // updating settings we want to update and backend (notify the rest of the participants)
  128. dispatch(setStartReactionsMuted(newState.startReactionsMuted, true));
  129. dispatch(updateSettings({ soundsReactions: !newState.startReactionsMuted }));
  130. });
  131. }
  132. if (newState.startAudioMuted !== currentState.startAudioMuted
  133. || newState.startVideoMuted !== currentState.startVideoMuted) {
  134. dispatch(setStartMutedPolicy(
  135. newState.startAudioMuted, newState.startVideoMuted));
  136. }
  137. };
  138. }
  139. /**
  140. * Submits the settings from the "Profile" tab of the settings dialog.
  141. *
  142. * @param {Object} newState - The new settings.
  143. * @returns {Function}
  144. */
  145. export function submitProfileTab(newState: Object): Function {
  146. return (dispatch, getState) => {
  147. const currentState = getProfileTabProps(getState());
  148. if (newState.displayName !== currentState.displayName) {
  149. APP.conference.changeLocalDisplayName(newState.displayName);
  150. }
  151. if (newState.email !== currentState.email) {
  152. APP.conference.changeLocalEmail(newState.email);
  153. }
  154. };
  155. }
  156. /**
  157. * Submits the settings from the "Sounds" tab of the settings dialog.
  158. *
  159. * @param {Object} newState - The new settings.
  160. * @returns {Function}
  161. */
  162. export function submitSoundsTab(newState: Object): Function {
  163. return (dispatch, getState) => {
  164. const currentState = getSoundsTabProps(getState());
  165. const shouldNotUpdateReactionSounds = getModeratorTabProps(getState()).startReactionsMuted;
  166. const shouldUpdate = (newState.soundsIncomingMessage !== currentState.soundsIncomingMessage)
  167. || (newState.soundsParticipantJoined !== currentState.soundsParticipantJoined)
  168. || (newState.soundsParticipantLeft !== currentState.soundsParticipantLeft)
  169. || (newState.soundsTalkWhileMuted !== currentState.soundsTalkWhileMuted)
  170. || (newState.soundsReactions !== currentState.soundsReactions);
  171. if (shouldUpdate) {
  172. const settingsToUpdate = {
  173. soundsIncomingMessage: newState.soundsIncomingMessage,
  174. soundsParticipantJoined: newState.soundsParticipantJoined,
  175. soundsParticipantLeft: newState.soundsParticipantLeft,
  176. soundsTalkWhileMuted: newState.soundsTalkWhileMuted,
  177. soundsReactions: newState.soundsReactions
  178. };
  179. if (shouldNotUpdateReactionSounds) {
  180. delete settingsToUpdate.soundsReactions;
  181. }
  182. dispatch(updateSettings(settingsToUpdate));
  183. }
  184. };
  185. }
  186. /**
  187. * Toggles the visibility of the audio settings.
  188. *
  189. * @returns {void}
  190. */
  191. export function toggleAudioSettings() {
  192. return (dispatch: Function, getState: Function) => {
  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: Function, getState: Function) => {
  204. const value = getState()['features/settings'].videoSettingsVisible;
  205. dispatch(setVideoSettingsVisibility(!value));
  206. };
  207. }