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

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