Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

middleware.native.ts 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { IStore } from '../../app/types';
  2. import { APP_WILL_MOUNT } from '../app/actionTypes';
  3. import { setAudioOnly } from '../audio-only/actions';
  4. import MiddlewareRegistry from '../redux/MiddlewareRegistry';
  5. import { SETTINGS_UPDATED } from './actionTypes';
  6. import { handleCallIntegrationChange, handleCrashReportingChange } from './functions.native';
  7. import { ISettingsState } from './reducer';
  8. import './middleware.any';
  9. /**
  10. * The middleware of the feature base/settings. Distributes changes to the state
  11. * of base/settings to the states of other features computed from the state of
  12. * base/settings.
  13. *
  14. * @param {Store} store - The redux store.
  15. * @returns {Function}
  16. */
  17. MiddlewareRegistry.register(store => next => action => {
  18. const result = next(action);
  19. switch (action.type) {
  20. case APP_WILL_MOUNT:
  21. _initializeCallIntegration(store);
  22. break;
  23. case SETTINGS_UPDATED:
  24. _maybeHandleCallIntegrationChange(action);
  25. _maybeCrashReportingChange(action);
  26. _maybeSetAudioOnly(store, action);
  27. break;
  28. }
  29. return result;
  30. });
  31. /**
  32. * Initializes the audio device handler based on the `disableCallIntegration` setting.
  33. *
  34. * @param {Store} store - The redux store.
  35. * @private
  36. * @returns {void}
  37. */
  38. function _initializeCallIntegration({ getState }: IStore) {
  39. const { disableCallIntegration } = getState()['features/base/settings'];
  40. if (typeof disableCallIntegration === 'boolean') {
  41. handleCallIntegrationChange(disableCallIntegration);
  42. }
  43. }
  44. /**
  45. * Handles a change in the `disableCallIntegration` setting.
  46. *
  47. * @param {Object} action - The redux action.
  48. * @private
  49. * @returns {void}
  50. */
  51. function _maybeHandleCallIntegrationChange({ settings: { disableCallIntegration } }: {
  52. settings: Partial<ISettingsState>;
  53. }) {
  54. if (typeof disableCallIntegration === 'boolean') {
  55. handleCallIntegrationChange(disableCallIntegration);
  56. }
  57. }
  58. /**
  59. * Handles a change in the `disableCrashReporting` setting.
  60. *
  61. * @param {Object} action - The redux action.
  62. * @private
  63. * @returns {void}
  64. */
  65. function _maybeCrashReportingChange({ settings: { disableCrashReporting } }: {
  66. settings: Partial<ISettingsState>;
  67. }) {
  68. if (typeof disableCrashReporting === 'boolean') {
  69. handleCrashReportingChange(disableCrashReporting);
  70. }
  71. }
  72. /**
  73. * Updates {@code startAudioOnly} flag if it's updated in the settings.
  74. *
  75. * @param {Store} store - The redux store.
  76. * @param {Object} action - The redux action.
  77. * @private
  78. * @returns {void}
  79. */
  80. function _maybeSetAudioOnly(
  81. { dispatch }: IStore,
  82. { settings: { startAudioOnly } }: { settings: Partial<ISettingsState>; }) {
  83. if (typeof startAudioOnly === 'boolean') {
  84. dispatch(setAudioOnly(startAudioOnly));
  85. }
  86. }