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

reducer.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // @flow
  2. import { jitsiLocalStorage } from '@jitsi/js-utils';
  3. import _ from 'lodash';
  4. import { APP_WILL_MOUNT } from '../app/actionTypes';
  5. import { PersistenceRegistry, ReducerRegistry } from '../redux';
  6. import { assignIfDefined } from '../util';
  7. import { SETTINGS_UPDATED } from './actionTypes';
  8. /**
  9. * The default/initial redux state of the feature {@code base/settings}.
  10. *
  11. * @type Object
  12. */
  13. const DEFAULT_STATE = {
  14. audioOutputDeviceId: undefined,
  15. avatarURL: undefined,
  16. cameraDeviceId: undefined,
  17. disableCallIntegration: undefined,
  18. disableCrashReporting: undefined,
  19. disableP2P: undefined,
  20. disableSelfView: false,
  21. displayName: undefined,
  22. email: undefined,
  23. localFlipX: true,
  24. micDeviceId: undefined,
  25. serverURL: undefined,
  26. hideShareAudioHelper: false,
  27. soundsIncomingMessage: true,
  28. soundsParticipantJoined: true,
  29. soundsParticipantKnocking: true,
  30. soundsParticipantLeft: true,
  31. soundsTalkWhileMuted: true,
  32. soundsReactions: true,
  33. startAudioOnly: false,
  34. startWithAudioMuted: false,
  35. startWithVideoMuted: false,
  36. userSelectedAudioOutputDeviceId: undefined,
  37. userSelectedCameraDeviceId: undefined,
  38. userSelectedMicDeviceId: undefined,
  39. userSelectedAudioOutputDeviceLabel: undefined,
  40. userSelectedCameraDeviceLabel: undefined,
  41. userSelectedNotifications: {
  42. 'notify.chatMessages': true
  43. },
  44. userSelectedMicDeviceLabel: undefined,
  45. userSelectedSkipPrejoin: undefined
  46. };
  47. const STORE_NAME = 'features/base/settings';
  48. /**
  49. * Sets up the persistence of the feature {@code base/settings}.
  50. */
  51. const filterSubtree = {};
  52. // start with the default state
  53. Object.keys(DEFAULT_STATE).forEach(key => {
  54. filterSubtree[key] = true;
  55. });
  56. // we want to filter these props, to not be stored as they represent
  57. // what is currently opened/used as devices
  58. filterSubtree.audioOutputDeviceId = false;
  59. filterSubtree.cameraDeviceId = false;
  60. filterSubtree.micDeviceId = false;
  61. PersistenceRegistry.register(STORE_NAME, filterSubtree, DEFAULT_STATE);
  62. ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
  63. switch (action.type) {
  64. case APP_WILL_MOUNT:
  65. return _initSettings(state);
  66. case SETTINGS_UPDATED:
  67. return {
  68. ...state,
  69. ...action.settings
  70. };
  71. }
  72. return state;
  73. });
  74. /**
  75. * Inits the settings object based on what information we have available.
  76. * Info taken into consideration:
  77. * - Old Settings.js style data.
  78. *
  79. * @private
  80. * @param {Object} featureState - The current state of the feature.
  81. * @returns {Object}
  82. */
  83. function _initSettings(featureState) {
  84. let settings = featureState;
  85. // Old Settings.js values
  86. // FIXME: jibri uses old settings.js local storage values to set its display
  87. // name and email. Provide another way for jibri to set these values, update
  88. // jibri, and remove the old settings.js values.
  89. const savedDisplayName = jitsiLocalStorage.getItem('displayname');
  90. const savedEmail = jitsiLocalStorage.getItem('email');
  91. // The helper _.escape will convert null to an empty strings. The empty
  92. // string will be saved in settings. On app re-load, because an empty string
  93. // is a defined value, it will override any value found in local storage.
  94. // The workaround is sidestepping _.escape when the value is not set in
  95. // local storage.
  96. const displayName = savedDisplayName === null ? undefined : _.escape(savedDisplayName);
  97. const email = savedEmail === null ? undefined : _.escape(savedEmail);
  98. settings = assignIfDefined({
  99. displayName,
  100. email
  101. }, settings);
  102. return settings;
  103. }