Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

middleware.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // @flow
  2. import { APP_WILL_MOUNT } from '../app';
  3. import { setAudioOnly } from '../audio-only';
  4. import { getLocalParticipant, participantUpdated } from '../participants';
  5. import { MiddlewareRegistry } from '../redux';
  6. import { SETTINGS_UPDATED } from './actionTypes';
  7. import { handleCallIntegrationChange } from './functions';
  8. /**
  9. * The middleware of the feature base/settings. Distributes changes to the state
  10. * of base/settings to the states of other features computed from the state of
  11. * base/settings.
  12. *
  13. * @param {Store} store - The redux store.
  14. * @returns {Function}
  15. */
  16. MiddlewareRegistry.register(store => next => action => {
  17. const result = next(action);
  18. switch (action.type) {
  19. case APP_WILL_MOUNT:
  20. _initializeCallIntegration(store);
  21. break;
  22. case SETTINGS_UPDATED:
  23. _maybeHandleCallIntegrationChange(action);
  24. _maybeSetAudioOnly(store, action);
  25. _updateLocalParticipant(store, action);
  26. break;
  27. }
  28. return result;
  29. });
  30. /**
  31. * Initializes the audio device handler based on the `disableCallIntegration` setting.
  32. *
  33. * @param {Store} store - The redux store.
  34. * @private
  35. * @returns {void}
  36. */
  37. function _initializeCallIntegration({ getState }) {
  38. const { disableCallIntegration } = getState()['features/base/settings'];
  39. if (typeof disableCallIntegration === 'boolean') {
  40. handleCallIntegrationChange(disableCallIntegration);
  41. }
  42. }
  43. /**
  44. * Maps the settings field names to participant names where they don't match.
  45. * Currently there is only one such field, but may be extended in the future.
  46. *
  47. * @private
  48. * @param {string} settingsField - The name of the settings field to map.
  49. * @returns {string}
  50. */
  51. function _mapSettingsFieldToParticipant(settingsField) {
  52. switch (settingsField) {
  53. case 'displayName':
  54. return 'name';
  55. }
  56. return settingsField;
  57. }
  58. /**
  59. * Handles a change in the `disableCallIntegration` setting.
  60. *
  61. * @param {Object} action - The redux action.
  62. * @private
  63. * @returns {void}
  64. */
  65. function _maybeHandleCallIntegrationChange({ settings: { disableCallIntegration } }) {
  66. if (typeof disableCallIntegration === 'boolean') {
  67. handleCallIntegrationChange(disableCallIntegration);
  68. }
  69. }
  70. /**
  71. * Updates {@code startAudioOnly} flag if it's updated in the settings.
  72. *
  73. * @param {Store} store - The redux store.
  74. * @param {Object} action - The redux action.
  75. * @private
  76. * @returns {void}
  77. */
  78. function _maybeSetAudioOnly(
  79. { dispatch },
  80. { settings: { startAudioOnly } }) {
  81. if (typeof startAudioOnly === 'boolean') {
  82. dispatch(setAudioOnly(startAudioOnly, true));
  83. }
  84. }
  85. /**
  86. * Updates the local participant according to settings changes.
  87. *
  88. * @param {Store} store - The redux store.
  89. * @param {Object} action - The dispatched action.
  90. * @private
  91. * @returns {void}
  92. */
  93. function _updateLocalParticipant({ dispatch, getState }, action) {
  94. const { settings } = action;
  95. const localParticipant = getLocalParticipant(getState());
  96. const newLocalParticipant = {
  97. ...localParticipant
  98. };
  99. for (const key in settings) {
  100. if (settings.hasOwnProperty(key)) {
  101. newLocalParticipant[_mapSettingsFieldToParticipant(key)]
  102. = settings[key];
  103. }
  104. }
  105. dispatch(participantUpdated(newLocalParticipant));
  106. }