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

middleware.ts 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import { AnyAction } from 'redux';
  2. import { IStore } from '../../app/types';
  3. import { SET_DYNAMIC_BRANDING_DATA } from '../../dynamic-branding/actionTypes';
  4. import { getFeatureFlag } from '../flags/functions';
  5. import MiddlewareRegistry from '../redux/MiddlewareRegistry';
  6. import { updateSettings } from '../settings/actions';
  7. import { OVERWRITE_CONFIG, SET_CONFIG } from './actionTypes';
  8. import { updateConfig } from './actions';
  9. import { IConfig } from './configType';
  10. /**
  11. * The middleware of the feature {@code base/config}.
  12. *
  13. * @param {Store} store - The redux store.
  14. * @private
  15. * @returns {Function}
  16. */
  17. MiddlewareRegistry.register(store => next => action => {
  18. switch (action.type) {
  19. case SET_CONFIG:
  20. return _setConfig(store, next, action);
  21. case SET_DYNAMIC_BRANDING_DATA:
  22. return _setDynamicBrandingData(store, next, action);
  23. case OVERWRITE_CONFIG:
  24. return _updateSettings(store, next, action);
  25. }
  26. return next(action);
  27. });
  28. /**
  29. * Notifies the feature {@code base/config} that the {@link SET_CONFIG} redux
  30. * action is being {@code dispatch}ed in a specific redux store.
  31. *
  32. * @param {Store} store - The redux store in which the specified {@code action}
  33. * is being dispatched.
  34. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  35. * specified {@code action} in the specified {@code store}.
  36. * @param {Action} action - The redux action which is being {@code dispatch}ed
  37. * in the specified {@code store}.
  38. * @private
  39. * @returns {*} The return value of {@code next(action)}.
  40. */
  41. function _setConfig({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
  42. // The reducer is doing some alterations to the config passed in the action,
  43. // so make sure it's the final state by waiting for the action to be
  44. // reduced.
  45. const result = next(action);
  46. const state = getState();
  47. // Update the config with user defined settings.
  48. const settings = state['features/base/settings'];
  49. const config: IConfig = {};
  50. if (typeof settings.disableP2P !== 'undefined') {
  51. config.p2p = { enabled: !settings.disableP2P };
  52. }
  53. const resolutionFlag = getFeatureFlag(state, 'resolution');
  54. if (typeof resolutionFlag !== 'undefined') {
  55. config.resolution = resolutionFlag;
  56. }
  57. if (action.config.doNotFlipLocalVideo === true) {
  58. dispatch(updateSettings({
  59. localFlipX: false
  60. }));
  61. }
  62. if (action.config.disableSelfView !== undefined) {
  63. dispatch(updateSettings({
  64. disableSelfView: action.config.disableSelfView
  65. }));
  66. }
  67. if (action.config.filmstrip?.stageFilmstripParticipants !== undefined) {
  68. dispatch(updateSettings({
  69. maxStageParticipants: action.config.filmstrip.stageFilmstripParticipants
  70. }));
  71. }
  72. dispatch(updateConfig(config));
  73. // FIXME On Web we rely on the global 'config' variable which gets altered
  74. // multiple times, before it makes it to the reducer. At some point it may
  75. // not be the global variable which is being modified anymore due to
  76. // different merge methods being used along the way. The global variable
  77. // must be synchronized with the final state resolved by the reducer.
  78. if (typeof window.config !== 'undefined') {
  79. window.config = state['features/base/config'];
  80. }
  81. return result;
  82. }
  83. /**
  84. * Updates config based on dynamic branding data.
  85. *
  86. * @param {Store} store - The redux store in which the specified {@code action}
  87. * is being dispatched.
  88. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  89. * specified {@code action} in the specified {@code store}.
  90. * @param {Action} action - The redux action which is being {@code dispatch}ed
  91. * in the specified {@code store}.
  92. * @private
  93. * @returns {*} The return value of {@code next(action)}.
  94. */
  95. function _setDynamicBrandingData({ dispatch }: IStore, next: Function, action: AnyAction) {
  96. const config: IConfig = {};
  97. const {
  98. downloadAppsUrl,
  99. liveStreamingDialogUrls = {},
  100. preCallTest = {},
  101. salesforceUrl,
  102. userDocumentationUrl
  103. } = action.value;
  104. const { helpUrl, termsUrl, dataPrivacyUrl } = liveStreamingDialogUrls;
  105. if (helpUrl || termsUrl || dataPrivacyUrl) {
  106. config.liveStreaming = {};
  107. if (helpUrl) {
  108. config.liveStreaming.helpLink = helpUrl;
  109. }
  110. if (termsUrl) {
  111. config.liveStreaming.termsLink = termsUrl;
  112. }
  113. if (dataPrivacyUrl) {
  114. config.liveStreaming.dataPrivacyLink = dataPrivacyUrl;
  115. }
  116. }
  117. if (downloadAppsUrl || userDocumentationUrl) {
  118. config.deploymentUrls = {};
  119. if (downloadAppsUrl) {
  120. config.deploymentUrls.downloadAppsUrl = downloadAppsUrl;
  121. }
  122. if (userDocumentationUrl) {
  123. config.deploymentUrls.userDocumentationURL = userDocumentationUrl;
  124. }
  125. }
  126. if (salesforceUrl) {
  127. config.salesforceUrl = salesforceUrl;
  128. }
  129. const { enabled, iceUrl } = preCallTest;
  130. if (typeof enabled === 'boolean') {
  131. config.prejoinConfig = {
  132. preCallTestEnabled: enabled
  133. };
  134. }
  135. if (iceUrl) {
  136. config.prejoinConfig = config.prejoinConfig || {};
  137. config.prejoinConfig.preCallTestICEUrl = iceUrl;
  138. }
  139. dispatch(updateConfig(config));
  140. return next(action);
  141. }
  142. /**
  143. * Updates settings based on some config values.
  144. *
  145. * @param {Store} store - The redux store in which the specified {@code action}
  146. * is being dispatched.
  147. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  148. * specified {@code action} in the specified {@code store}.
  149. * @param {Action} action - The redux action which is being {@code dispatch}ed
  150. * in the specified {@code store}.
  151. * @private
  152. * @returns {*} The return value of {@code next(action)}.
  153. */
  154. function _updateSettings({ dispatch }: IStore, next: Function, action: AnyAction) {
  155. const { config: { doNotFlipLocalVideo } } = action;
  156. if (doNotFlipLocalVideo === true) {
  157. dispatch(updateSettings({
  158. localFlipX: false
  159. }));
  160. }
  161. return next(action);
  162. }