選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

actions.web.ts 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 { getLocalVideoTrack } from '../base/tracks/functions.any';
  12. import { disableKeyboardShortcuts, enableKeyboardShortcuts } from '../keyboard-shortcuts/actions';
  13. import { toggleBackgroundEffect } from '../virtual-background/actions';
  14. import virtualBackgroundLogger from '../virtual-background/logger';
  15. import {
  16. SET_AUDIO_SETTINGS_VISIBILITY,
  17. SET_VIDEO_SETTINGS_VISIBILITY
  18. } from './actionTypes';
  19. import LogoutDialog from './components/web/LogoutDialog';
  20. import SettingsDialog from './components/web/SettingsDialog';
  21. import {
  22. getModeratorTabProps,
  23. getMoreTabProps,
  24. getNotificationsTabProps,
  25. getProfileTabProps,
  26. getShortcutsTabProps
  27. } from './functions.web';
  28. /**
  29. * Opens {@code LogoutDialog}.
  30. *
  31. * @param {Function} onLogout - The event in {@code LogoutDialog} that should be
  32. * enabled on click.
  33. * @returns {Function}
  34. */
  35. export function openLogoutDialog(onLogout: Function) {
  36. return openDialog(LogoutDialog, { onLogout });
  37. }
  38. /**
  39. * Opens {@code SettingsDialog}.
  40. *
  41. * @param {string} defaultTab - The tab in {@code SettingsDialog} that should be
  42. * displayed initially.
  43. * @param {boolean} isDisplayedOnWelcomePage - Indicates whether the device selection dialog is displayed on the
  44. * welcome page or not.
  45. * @returns {Function}
  46. */
  47. export function openSettingsDialog(defaultTab: string, isDisplayedOnWelcomePage?: boolean) {
  48. return openDialog(SettingsDialog, {
  49. defaultTab,
  50. isDisplayedOnWelcomePage
  51. });
  52. }
  53. /**
  54. * Sets the visibility of the audio settings.
  55. *
  56. * @param {boolean} value - The new value.
  57. * @returns {Function}
  58. */
  59. function setAudioSettingsVisibility(value: boolean) {
  60. return {
  61. type: SET_AUDIO_SETTINGS_VISIBILITY,
  62. value
  63. };
  64. }
  65. /**
  66. * Sets the visibility of the video settings.
  67. *
  68. * @param {boolean} value - The new value.
  69. * @returns {Function}
  70. */
  71. function setVideoSettingsVisibility(value: boolean) {
  72. return {
  73. type: SET_VIDEO_SETTINGS_VISIBILITY,
  74. value
  75. };
  76. }
  77. /**
  78. * Submits the settings from the "More" tab of the settings dialog.
  79. *
  80. * @param {Object} newState - The new settings.
  81. * @returns {Function}
  82. */
  83. export function submitMoreTab(newState: any) {
  84. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  85. const currentState = getMoreTabProps(getState());
  86. const showPrejoinPage = newState.showPrejoinPage;
  87. if (showPrejoinPage !== currentState.showPrejoinPage) {
  88. dispatch(updateSettings({
  89. userSelectedSkipPrejoin: !showPrejoinPage
  90. }));
  91. }
  92. if (newState.maxStageParticipants !== currentState.maxStageParticipants) {
  93. dispatch(updateSettings({ maxStageParticipants: Number(newState.maxStageParticipants) }));
  94. }
  95. };
  96. }
  97. /**
  98. * Submits the settings from the "Moderator" tab of the settings dialog.
  99. *
  100. * @param {Object} newState - The new settings.
  101. * @returns {Function}
  102. */
  103. export function submitModeratorTab(newState: any) {
  104. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  105. const currentState = getModeratorTabProps(getState());
  106. if (newState.followMeEnabled !== currentState.followMeEnabled) {
  107. dispatch(setFollowMe(newState.followMeEnabled));
  108. }
  109. if (newState.startReactionsMuted !== currentState.startReactionsMuted) {
  110. batch(() => {
  111. // updating settings we want to update and backend (notify the rest of the participants)
  112. dispatch(setStartReactionsMuted(newState.startReactionsMuted, true));
  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: any) {
  130. return (dispatch: IStore['dispatch'], getState: IStore['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. if (newState.hideSelfView !== currentState.hideSelfView) {
  139. dispatch(updateSettings({ disableSelfView: newState.hideSelfView }));
  140. }
  141. if (newState.currentLanguage !== currentState.currentLanguage) {
  142. i18next.changeLanguage(newState.currentLanguage);
  143. }
  144. };
  145. }
  146. /**
  147. * Submits the settings from the "Sounds" tab of the settings dialog.
  148. *
  149. * @param {Object} newState - The new settings.
  150. * @returns {Function}
  151. */
  152. export function submitNotificationsTab(newState: any) {
  153. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  154. const currentState = getNotificationsTabProps(getState());
  155. const shouldNotUpdateReactionSounds = getModeratorTabProps(getState()).startReactionsMuted;
  156. const shouldUpdate = (newState.soundsIncomingMessage !== currentState.soundsIncomingMessage)
  157. || (newState.soundsParticipantJoined !== currentState.soundsParticipantJoined)
  158. || (newState.soundsParticipantKnocking !== currentState.soundsParticipantKnocking)
  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. soundsParticipantKnocking: newState.soundsParticipantKnocking,
  167. soundsParticipantLeft: newState.soundsParticipantLeft,
  168. soundsTalkWhileMuted: newState.soundsTalkWhileMuted,
  169. soundsReactions: newState.soundsReactions
  170. };
  171. if (shouldNotUpdateReactionSounds) {
  172. delete settingsToUpdate.soundsReactions;
  173. }
  174. dispatch(updateSettings(settingsToUpdate));
  175. }
  176. const enabledNotifications = newState.enabledNotifications;
  177. if (enabledNotifications !== currentState.enabledNotifications) {
  178. dispatch(updateSettings({
  179. userSelectedNotifications: {
  180. ...getState()['features/base/settings'].userSelectedNotifications,
  181. ...enabledNotifications
  182. }
  183. }));
  184. }
  185. };
  186. }
  187. /**
  188. * Toggles the visibility of the audio settings.
  189. *
  190. * @returns {void}
  191. */
  192. export function toggleAudioSettings() {
  193. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  194. const value = getState()['features/settings'].audioSettingsVisible;
  195. dispatch(setAudioSettingsVisibility(!value));
  196. };
  197. }
  198. /**
  199. * Toggles the visibility of the video settings.
  200. *
  201. * @returns {void}
  202. */
  203. export function toggleVideoSettings() {
  204. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  205. const value = getState()['features/settings'].videoSettingsVisible;
  206. dispatch(setVideoSettingsVisibility(!value));
  207. };
  208. }
  209. /**
  210. * Submits the settings from the "Shortcuts" tab of the settings dialog.
  211. *
  212. * @param {Object} newState - The new settings.
  213. * @returns {Function}
  214. */
  215. export function submitShortcutsTab(newState: any) {
  216. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  217. const currentState = getShortcutsTabProps(getState());
  218. if (newState.keyboardShortcutsEnabled !== currentState.keyboardShortcutsEnabled) {
  219. if (newState.keyboardShortcutsEnabled) {
  220. dispatch(enableKeyboardShortcuts());
  221. } else {
  222. dispatch(disableKeyboardShortcuts());
  223. }
  224. }
  225. };
  226. }
  227. /**
  228. * Submits the settings from the "Virtual Background" tab of the settings dialog.
  229. *
  230. * @param {Object} newState - The new settings.
  231. * @param {boolean} isCancel - Whether the change represents a cancel.
  232. * @returns {Function}
  233. */
  234. export function submitVirtualBackgroundTab(newState: any, isCancel = false) {
  235. return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  236. const state = getState();
  237. const track = getLocalVideoTrack(state['features/base/tracks'])?.jitsiTrack;
  238. if (newState.options?.selectedThumbnail) {
  239. await dispatch(toggleBackgroundEffect(newState.options, track));
  240. if (!isCancel) {
  241. // Set x scale to default value.
  242. dispatch(updateSettings({
  243. localFlipX: true
  244. }));
  245. virtualBackgroundLogger.info(`Virtual background type: '${
  246. typeof newState.options.backgroundType === 'undefined'
  247. ? 'none' : newState.options.backgroundType}' applied!`);
  248. }
  249. }
  250. };
  251. }