您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.ts 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import { batch } from 'react-redux';
  2. import { IStore } from '../app/types';
  3. import {
  4. setFollowMe,
  5. setStartMutedPolicy,
  6. setStartReactionsMuted
  7. } from '../base/conference/actions';
  8. import { openDialog } from '../base/dialog/actions';
  9. import i18next from '../base/i18n/i18next';
  10. import { updateSettings } from '../base/settings/actions';
  11. import { setScreenshareFramerate } from '../screen-share/actions';
  12. import {
  13. SET_AUDIO_SETTINGS_VISIBILITY,
  14. SET_VIDEO_SETTINGS_VISIBILITY
  15. } from './actionTypes';
  16. // eslint-disable-next-line lines-around-comment
  17. // @ts-ignore
  18. import { LogoutDialog, SettingsDialog } from './components';
  19. import {
  20. getModeratorTabProps,
  21. getMoreTabProps,
  22. getProfileTabProps,
  23. getSoundsTabProps
  24. } from './functions';
  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. * @param {boolean} isDisplayedOnWelcomePage - Indicates whether the device selection dialog is displayed on the
  41. * welcome page or not.
  42. * @returns {Function}
  43. */
  44. export function openSettingsDialog(defaultTab: string, isDisplayedOnWelcomePage?: boolean) {
  45. return openDialog(SettingsDialog, {
  46. defaultTab,
  47. isDisplayedOnWelcomePage
  48. });
  49. }
  50. /**
  51. * Sets the visibility of the audio settings.
  52. *
  53. * @param {boolean} value - The new value.
  54. * @returns {Function}
  55. */
  56. function setAudioSettingsVisibility(value: boolean) {
  57. return {
  58. type: SET_AUDIO_SETTINGS_VISIBILITY,
  59. value
  60. };
  61. }
  62. /**
  63. * Sets the visibility of the video settings.
  64. *
  65. * @param {boolean} value - The new value.
  66. * @returns {Function}
  67. */
  68. function setVideoSettingsVisibility(value: boolean) {
  69. return {
  70. type: SET_VIDEO_SETTINGS_VISIBILITY,
  71. value
  72. };
  73. }
  74. /**
  75. * Submits the settings from the "More" tab of the settings dialog.
  76. *
  77. * @param {Object} newState - The new settings.
  78. * @returns {Function}
  79. */
  80. export function submitMoreTab(newState: any) {
  81. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  82. const currentState = getMoreTabProps(getState());
  83. const showPrejoinPage = newState.showPrejoinPage;
  84. if (showPrejoinPage !== currentState.showPrejoinPage) {
  85. dispatch(updateSettings({
  86. userSelectedSkipPrejoin: !showPrejoinPage
  87. }));
  88. }
  89. const enabledNotifications = newState.enabledNotifications;
  90. if (enabledNotifications !== currentState.enabledNotifications) {
  91. dispatch(updateSettings({
  92. userSelectedNotifications: {
  93. ...getState()['features/base/settings'].userSelectedNotifications,
  94. ...enabledNotifications
  95. }
  96. }));
  97. }
  98. if (newState.currentLanguage !== currentState.currentLanguage) {
  99. i18next.changeLanguage(newState.currentLanguage);
  100. }
  101. if (newState.currentFramerate !== currentState.currentFramerate) {
  102. const frameRate = parseInt(newState.currentFramerate, 10);
  103. dispatch(setScreenshareFramerate(frameRate));
  104. }
  105. if (newState.hideSelfView !== currentState.hideSelfView) {
  106. dispatch(updateSettings({ disableSelfView: newState.hideSelfView }));
  107. }
  108. if (newState.maxStageParticipants !== currentState.maxStageParticipants) {
  109. dispatch(updateSettings({ maxStageParticipants: Number(newState.maxStageParticipants) }));
  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: any) {
  120. return (dispatch: IStore['dispatch'], getState: IStore['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: any) {
  146. return (dispatch: IStore['dispatch'], getState: IStore['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: any) {
  163. return (dispatch: IStore['dispatch'], getState: IStore['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.soundsParticipantKnocking !== currentState.soundsParticipantKnocking)
  169. || (newState.soundsParticipantLeft !== currentState.soundsParticipantLeft)
  170. || (newState.soundsTalkWhileMuted !== currentState.soundsTalkWhileMuted)
  171. || (newState.soundsReactions !== currentState.soundsReactions);
  172. if (shouldUpdate) {
  173. const settingsToUpdate = {
  174. soundsIncomingMessage: newState.soundsIncomingMessage,
  175. soundsParticipantJoined: newState.soundsParticipantJoined,
  176. soundsParticipantKnocking: newState.soundsParticipantKnocking,
  177. soundsParticipantLeft: newState.soundsParticipantLeft,
  178. soundsTalkWhileMuted: newState.soundsTalkWhileMuted,
  179. soundsReactions: newState.soundsReactions
  180. };
  181. if (shouldNotUpdateReactionSounds) {
  182. delete settingsToUpdate.soundsReactions;
  183. }
  184. dispatch(updateSettings(settingsToUpdate));
  185. }
  186. };
  187. }
  188. /**
  189. * Toggles the visibility of the audio settings.
  190. *
  191. * @returns {void}
  192. */
  193. export function toggleAudioSettings() {
  194. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  195. const value = getState()['features/settings'].audioSettingsVisible;
  196. dispatch(setAudioSettingsVisibility(!value));
  197. };
  198. }
  199. /**
  200. * Toggles the visibility of the video settings.
  201. *
  202. * @returns {void}
  203. */
  204. export function toggleVideoSettings() {
  205. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  206. const value = getState()['features/settings'].videoSettingsVisible;
  207. dispatch(setVideoSettingsVisibility(!value));
  208. };
  209. }