You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reducer.js 3.4KB

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