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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 { setMaxStageParticipants } from '../filmstrip/actions.web';
  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. dispatch(updateSettings({
  81. userSelectedSkipPrejoin: !showPrejoinPage
  82. }));
  83. }
  84. const enabledNotifications = newState.enabledNotifications;
  85. if (enabledNotifications !== currentState.enabledNotifications) {
  86. dispatch(updateSettings({
  87. userSelectedNotifications: {
  88. ...getState()['features/base/settings'].userSelectedNotifications,
  89. ...enabledNotifications
  90. }
  91. }));
  92. }
  93. if (newState.currentLanguage !== currentState.currentLanguage) {
  94. i18next.changeLanguage(newState.currentLanguage);
  95. }
  96. if (newState.currentFramerate !== currentState.currentFramerate) {
  97. const frameRate = parseInt(newState.currentFramerate, 10);
  98. dispatch(setScreenshareFramerate(frameRate));
  99. }
  100. if (newState.hideSelfView !== currentState.hideSelfView) {
  101. dispatch(updateSettings({ disableSelfView: newState.hideSelfView }));
  102. }
  103. if (Number(newState.maxStageParticipants) !== currentState.maxStageParticipants) {
  104. dispatch(setMaxStageParticipants(Number(newState.maxStageParticipants)));
  105. }
  106. };
  107. }
  108. /**
  109. * Submits the settings from the "Moderator" tab of the settings dialog.
  110. *
  111. * @param {Object} newState - The new settings.
  112. * @returns {Function}
  113. */
  114. export function submitModeratorTab(newState: Object): Function {
  115. return (dispatch, getState) => {
  116. const currentState = getModeratorTabProps(getState());
  117. if (newState.followMeEnabled !== currentState.followMeEnabled) {
  118. dispatch(setFollowMe(newState.followMeEnabled));
  119. }
  120. if (newState.startReactionsMuted !== currentState.startReactionsMuted) {
  121. batch(() => {
  122. // updating settings we want to update and backend (notify the rest of the participants)
  123. dispatch(setStartReactionsMuted(newState.startReactionsMuted, true));
  124. dispatch(updateSettings({ soundsReactions: !newState.startReactionsMuted }));
  125. });
  126. }
  127. if (newState.startAudioMuted !== currentState.startAudioMuted
  128. || newState.startVideoMuted !== currentState.startVideoMuted) {
  129. dispatch(setStartMutedPolicy(
  130. newState.startAudioMuted, newState.startVideoMuted));
  131. }
  132. };
  133. }
  134. /**
  135. * Submits the settings from the "Profile" tab of the settings dialog.
  136. *
  137. * @param {Object} newState - The new settings.
  138. * @returns {Function}
  139. */
  140. export function submitProfileTab(newState: Object): Function {
  141. return (dispatch, getState) => {
  142. const currentState = getProfileTabProps(getState());
  143. if (newState.displayName !== currentState.displayName) {
  144. APP.conference.changeLocalDisplayName(newState.displayName);
  145. }
  146. if (newState.email !== currentState.email) {
  147. APP.conference.changeLocalEmail(newState.email);
  148. }
  149. };
  150. }
  151. /**
  152. * Submits the settings from the "Sounds" tab of the settings dialog.
  153. *
  154. * @param {Object} newState - The new settings.
  155. * @returns {Function}
  156. */
  157. export function submitSoundsTab(newState: Object): Function {
  158. return (dispatch, getState) => {
  159. const currentState = getSoundsTabProps(getState());
  160. const shouldNotUpdateReactionSounds = getModeratorTabProps(getState()).startReactionsMuted;
  161. const shouldUpdate = (newState.soundsIncomingMessage !== currentState.soundsIncomingMessage)
  162. || (newState.soundsParticipantJoined !== currentState.soundsParticipantJoined)
  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. soundsParticipantLeft: newState.soundsParticipantLeft,
  171. soundsTalkWhileMuted: newState.soundsTalkWhileMuted,
  172. soundsReactions: newState.soundsReactions
  173. };
  174. if (shouldNotUpdateReactionSounds) {
  175. delete settingsToUpdate.soundsReactions;
  176. }
  177. dispatch(updateSettings(settingsToUpdate));
  178. }
  179. };
  180. }
  181. /**
  182. * Toggles the visibility of the audio settings.
  183. *
  184. * @returns {void}
  185. */
  186. export function toggleAudioSettings() {
  187. return (dispatch: Function, getState: Function) => {
  188. const value = getState()['features/settings'].audioSettingsVisible;
  189. dispatch(setAudioSettingsVisibility(!value));
  190. };
  191. }
  192. /**
  193. * Toggles the visibility of the video settings.
  194. *
  195. * @returns {void}
  196. */
  197. export function toggleVideoSettings() {
  198. return (dispatch: Function, getState: Function) => {
  199. const value = getState()['features/settings'].videoSettingsVisible;
  200. dispatch(setVideoSettingsVisibility(!value));
  201. };
  202. }