Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

actions.web.ts 11KB

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