Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

actions.js 6.9KB

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