Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

reducer.js 3.5KB

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