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

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