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.web.ts 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. import { batch } from 'react-redux';
  2. import { IStore } from '../app/types';
  3. import { setTokenAuthUrlSuccess } from '../authentication/actions.web';
  4. import { isTokenAuthEnabled } from '../authentication/functions';
  5. import {
  6. setFollowMe,
  7. setFollowMeRecorder,
  8. setStartMutedPolicy,
  9. setStartReactionsMuted
  10. } from '../base/conference/actions';
  11. import { hangup } from '../base/connection/actions.web';
  12. import { openDialog } from '../base/dialog/actions';
  13. import i18next from '../base/i18n/i18next';
  14. import { browser } from '../base/lib-jitsi-meet';
  15. import { getNormalizedDisplayName } from '../base/participants/functions';
  16. import { updateSettings } from '../base/settings/actions';
  17. import { getLocalVideoTrack } from '../base/tracks/functions.web';
  18. import { appendURLHashParam } from '../base/util/uri';
  19. import { disableKeyboardShortcuts, enableKeyboardShortcuts } from '../keyboard-shortcuts/actions';
  20. import { toggleBackgroundEffect } from '../virtual-background/actions';
  21. import virtualBackgroundLogger from '../virtual-background/logger';
  22. import {
  23. SET_AUDIO_SETTINGS_VISIBILITY,
  24. SET_VIDEO_SETTINGS_VISIBILITY
  25. } from './actionTypes';
  26. import LogoutDialog from './components/web/LogoutDialog';
  27. import SettingsDialog from './components/web/SettingsDialog';
  28. import {
  29. getModeratorTabProps,
  30. getMoreTabProps,
  31. getNotificationsTabProps,
  32. getProfileTabProps,
  33. getShortcutsTabProps
  34. } from './functions.web';
  35. /**
  36. * Opens {@code LogoutDialog}.
  37. *
  38. * @returns {Function}
  39. */
  40. export function openLogoutDialog() {
  41. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  42. const state = getState();
  43. const config = state['features/base/config'];
  44. const logoutUrl = config.tokenLogoutUrl;
  45. const { conference } = state['features/base/conference'];
  46. const { jwt } = state['features/base/jwt'];
  47. dispatch(openDialog(LogoutDialog, {
  48. onLogout() {
  49. if (isTokenAuthEnabled(config) && config.tokenAuthUrlAutoRedirect && jwt) {
  50. // user is logging out remove auto redirect indication
  51. dispatch(setTokenAuthUrlSuccess(false));
  52. }
  53. if (logoutUrl && browser.isElectron()) {
  54. const url = appendURLHashParam(logoutUrl, 'electron', 'true');
  55. window.open(url, '_blank');
  56. dispatch(hangup(true));
  57. } else {
  58. if (logoutUrl) {
  59. window.location.href = logoutUrl;
  60. return;
  61. }
  62. conference?.room.xmpp.moderator.logout(() => dispatch(hangup(true)));
  63. }
  64. }
  65. }));
  66. };
  67. }
  68. /**
  69. * Opens {@code SettingsDialog}.
  70. *
  71. * @param {string} defaultTab - The tab in {@code SettingsDialog} that should be
  72. * displayed initially.
  73. * @param {boolean} isDisplayedOnWelcomePage - Indicates whether the device selection dialog is displayed on the
  74. * welcome page or not.
  75. * @returns {Function}
  76. */
  77. export function openSettingsDialog(defaultTab?: string, isDisplayedOnWelcomePage?: boolean) {
  78. return openDialog(SettingsDialog, {
  79. defaultTab,
  80. isDisplayedOnWelcomePage
  81. });
  82. }
  83. /**
  84. * Sets the visibility of the audio settings.
  85. *
  86. * @param {boolean} value - The new value.
  87. * @returns {Function}
  88. */
  89. function setAudioSettingsVisibility(value: boolean) {
  90. return {
  91. type: SET_AUDIO_SETTINGS_VISIBILITY,
  92. value
  93. };
  94. }
  95. /**
  96. * Sets the visibility of the video settings.
  97. *
  98. * @param {boolean} value - The new value.
  99. * @returns {Function}
  100. */
  101. function setVideoSettingsVisibility(value: boolean) {
  102. return {
  103. type: SET_VIDEO_SETTINGS_VISIBILITY,
  104. value
  105. };
  106. }
  107. /**
  108. * Submits the settings from the "More" tab of the settings dialog.
  109. *
  110. * @param {Object} newState - The new settings.
  111. * @returns {Function}
  112. */
  113. export function submitMoreTab(newState: any) {
  114. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  115. const currentState = getMoreTabProps(getState());
  116. const showPrejoinPage = newState.showPrejoinPage;
  117. if (showPrejoinPage !== currentState.showPrejoinPage) {
  118. dispatch(updateSettings({
  119. userSelectedSkipPrejoin: !showPrejoinPage
  120. }));
  121. }
  122. if (newState.maxStageParticipants !== currentState.maxStageParticipants) {
  123. dispatch(updateSettings({ maxStageParticipants: Number(newState.maxStageParticipants) }));
  124. }
  125. if (newState.hideSelfView !== currentState.hideSelfView) {
  126. dispatch(updateSettings({ disableSelfView: newState.hideSelfView }));
  127. }
  128. if (newState.currentLanguage !== currentState.currentLanguage) {
  129. i18next.changeLanguage(newState.currentLanguage);
  130. }
  131. };
  132. }
  133. /**
  134. * Submits the settings from the "Moderator" tab of the settings dialog.
  135. *
  136. * @param {Object} newState - The new settings.
  137. * @returns {Function}
  138. */
  139. export function submitModeratorTab(newState: any) {
  140. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  141. const currentState = getModeratorTabProps(getState());
  142. if (newState.followMeEnabled !== currentState.followMeEnabled) {
  143. dispatch(setFollowMe(newState.followMeEnabled));
  144. }
  145. if (newState.followMeRecorderEnabled !== currentState.followMeRecorderEnabled) {
  146. dispatch(setFollowMeRecorder(newState.followMeRecorderEnabled));
  147. }
  148. if (newState.startReactionsMuted !== currentState.startReactionsMuted) {
  149. batch(() => {
  150. // updating settings we want to update and backend (notify the rest of the participants)
  151. dispatch(setStartReactionsMuted(newState.startReactionsMuted, true));
  152. dispatch(updateSettings({ soundsReactions: !newState.startReactionsMuted }));
  153. });
  154. }
  155. if (newState.startAudioMuted !== currentState.startAudioMuted
  156. || newState.startVideoMuted !== currentState.startVideoMuted) {
  157. dispatch(setStartMutedPolicy(
  158. newState.startAudioMuted, newState.startVideoMuted));
  159. }
  160. };
  161. }
  162. /**
  163. * Submits the settings from the "Profile" tab of the settings dialog.
  164. *
  165. * @param {Object} newState - The new settings.
  166. * @returns {Function}
  167. */
  168. export function submitProfileTab(newState: any) {
  169. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  170. const currentState = getProfileTabProps(getState());
  171. if (newState.displayName !== currentState.displayName) {
  172. dispatch(updateSettings({ displayName: getNormalizedDisplayName(newState.displayName) }));
  173. }
  174. if (newState.email !== currentState.email) {
  175. APP.conference.changeLocalEmail(newState.email);
  176. }
  177. };
  178. }
  179. /**
  180. * Submits the settings from the "Sounds" tab of the settings dialog.
  181. *
  182. * @param {Object} newState - The new settings.
  183. * @returns {Function}
  184. */
  185. export function submitNotificationsTab(newState: any) {
  186. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  187. const currentState = getNotificationsTabProps(getState());
  188. const shouldNotUpdateReactionSounds = getModeratorTabProps(getState()).startReactionsMuted;
  189. const shouldUpdate = (newState.soundsIncomingMessage !== currentState.soundsIncomingMessage)
  190. || (newState.soundsParticipantJoined !== currentState.soundsParticipantJoined)
  191. || (newState.soundsParticipantKnocking !== currentState.soundsParticipantKnocking)
  192. || (newState.soundsParticipantLeft !== currentState.soundsParticipantLeft)
  193. || (newState.soundsTalkWhileMuted !== currentState.soundsTalkWhileMuted)
  194. || (newState.soundsReactions !== currentState.soundsReactions);
  195. if (shouldUpdate) {
  196. const settingsToUpdate = {
  197. soundsIncomingMessage: newState.soundsIncomingMessage,
  198. soundsParticipantJoined: newState.soundsParticipantJoined,
  199. soundsParticipantKnocking: newState.soundsParticipantKnocking,
  200. soundsParticipantLeft: newState.soundsParticipantLeft,
  201. soundsTalkWhileMuted: newState.soundsTalkWhileMuted,
  202. soundsReactions: newState.soundsReactions
  203. };
  204. if (shouldNotUpdateReactionSounds) {
  205. delete settingsToUpdate.soundsReactions;
  206. }
  207. dispatch(updateSettings(settingsToUpdate));
  208. }
  209. const enabledNotifications = newState.enabledNotifications;
  210. if (enabledNotifications !== currentState.enabledNotifications) {
  211. dispatch(updateSettings({
  212. userSelectedNotifications: {
  213. ...getState()['features/base/settings'].userSelectedNotifications,
  214. ...enabledNotifications
  215. }
  216. }));
  217. }
  218. };
  219. }
  220. /**
  221. * Toggles the visibility of the audio settings.
  222. *
  223. * @returns {void}
  224. */
  225. export function toggleAudioSettings() {
  226. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  227. const value = getState()['features/settings'].audioSettingsVisible;
  228. dispatch(setAudioSettingsVisibility(!value));
  229. };
  230. }
  231. /**
  232. * Toggles the visibility of the video settings.
  233. *
  234. * @returns {void}
  235. */
  236. export function toggleVideoSettings() {
  237. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  238. const value = getState()['features/settings'].videoSettingsVisible;
  239. dispatch(setVideoSettingsVisibility(!value));
  240. };
  241. }
  242. /**
  243. * Submits the settings from the "Shortcuts" tab of the settings dialog.
  244. *
  245. * @param {Object} newState - The new settings.
  246. * @returns {Function}
  247. */
  248. export function submitShortcutsTab(newState: any) {
  249. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  250. const currentState = getShortcutsTabProps(getState());
  251. if (newState.keyboardShortcutsEnabled !== currentState.keyboardShortcutsEnabled) {
  252. if (newState.keyboardShortcutsEnabled) {
  253. dispatch(enableKeyboardShortcuts());
  254. } else {
  255. dispatch(disableKeyboardShortcuts());
  256. }
  257. }
  258. };
  259. }
  260. /**
  261. * Submits the settings from the "Virtual Background" tab of the settings dialog.
  262. *
  263. * @param {Object} newState - The new settings.
  264. * @param {boolean} isCancel - Whether the change represents a cancel.
  265. * @returns {Function}
  266. */
  267. export function submitVirtualBackgroundTab(newState: any, isCancel = false) {
  268. return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  269. const state = getState();
  270. const track = getLocalVideoTrack(state['features/base/tracks'])?.jitsiTrack;
  271. const { localFlipX } = state['features/base/settings'];
  272. if (newState.options?.selectedThumbnail) {
  273. await dispatch(toggleBackgroundEffect(newState.options, track));
  274. if (!isCancel) {
  275. // Set x scale to default value.
  276. dispatch(updateSettings({
  277. localFlipX
  278. }));
  279. virtualBackgroundLogger.info(`Virtual background type: '${
  280. typeof newState.options.backgroundType === 'undefined'
  281. ? 'none' : newState.options.backgroundType}' applied!`);
  282. }
  283. }
  284. };
  285. }