Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

middleware.ts 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { AnyAction } from 'redux';
  2. import { IStore } from '../../app/types';
  3. import { getFeatureFlag } from '../flags/functions';
  4. import MiddlewareRegistry from '../redux/MiddlewareRegistry';
  5. import { updateSettings } from '../settings/actions';
  6. import { OVERWRITE_CONFIG, SET_CONFIG } from './actionTypes';
  7. import { updateConfig } from './actions';
  8. import { IConfig } from './configType';
  9. /**
  10. * The middleware of the feature {@code base/config}.
  11. *
  12. * @param {Store} store - The redux store.
  13. * @private
  14. * @returns {Function}
  15. */
  16. MiddlewareRegistry.register(store => next => action => {
  17. switch (action.type) {
  18. case SET_CONFIG:
  19. return _setConfig(store, next, action);
  20. case OVERWRITE_CONFIG:
  21. return _updateSettings(store, next, action);
  22. }
  23. return next(action);
  24. });
  25. /**
  26. * Notifies the feature {@code base/config} that the {@link SET_CONFIG} redux
  27. * action is being {@code dispatch}ed in a specific redux store.
  28. *
  29. * @param {Store} store - The redux store in which the specified {@code action}
  30. * is being dispatched.
  31. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  32. * specified {@code action} in the specified {@code store}.
  33. * @param {Action} action - The redux action which is being {@code dispatch}ed
  34. * in the specified {@code store}.
  35. * @private
  36. * @returns {*} The return value of {@code next(action)}.
  37. */
  38. function _setConfig({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
  39. // The reducer is doing some alterations to the config passed in the action,
  40. // so make sure it's the final state by waiting for the action to be
  41. // reduced.
  42. const result = next(action);
  43. const state = getState();
  44. // Update the config with user defined settings.
  45. const settings = state['features/base/settings'];
  46. const config: IConfig = {};
  47. // FIXME: P2P is currently temporality disabled on mobile.
  48. // eslint-disable-next-line no-constant-condition
  49. if (false && typeof settings.disableP2P !== 'undefined') {
  50. config.p2p = { enabled: !settings.disableP2P };
  51. }
  52. const resolutionFlag = getFeatureFlag(state, 'resolution');
  53. if (typeof resolutionFlag !== 'undefined') {
  54. config.resolution = resolutionFlag;
  55. }
  56. if (action.config.doNotFlipLocalVideo === true) {
  57. dispatch(updateSettings({
  58. localFlipX: false
  59. }));
  60. }
  61. if (action.config.disableSelfView !== undefined) {
  62. dispatch(updateSettings({
  63. disableSelfView: action.config.disableSelfView
  64. }));
  65. }
  66. if (action.config.filmstrip?.stageFilmstripParticipants !== undefined) {
  67. dispatch(updateSettings({
  68. maxStageParticipants: action.config.filmstrip.stageFilmstripParticipants
  69. }));
  70. }
  71. dispatch(updateConfig(config));
  72. // FIXME On Web we rely on the global 'config' variable which gets altered
  73. // multiple times, before it makes it to the reducer. At some point it may
  74. // not be the global variable which is being modified anymore due to
  75. // different merge methods being used along the way. The global variable
  76. // must be synchronized with the final state resolved by the reducer.
  77. if (typeof window.config !== 'undefined') {
  78. window.config = state['features/base/config'];
  79. }
  80. return result;
  81. }
  82. /**
  83. * Updates settings based on some config values.
  84. *
  85. * @param {Store} store - The redux store in which the specified {@code action}
  86. * is being dispatched.
  87. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  88. * specified {@code action} in the specified {@code store}.
  89. * @param {Action} action - The redux action which is being {@code dispatch}ed
  90. * in the specified {@code store}.
  91. * @private
  92. * @returns {*} The return value of {@code next(action)}.
  93. */
  94. function _updateSettings({ dispatch }: IStore, next: Function, action: AnyAction) {
  95. const { config: { doNotFlipLocalVideo } } = action;
  96. if (doNotFlipLocalVideo === true) {
  97. dispatch(updateSettings({
  98. localFlipX: false
  99. }));
  100. }
  101. return next(action);
  102. }