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

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