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.2KB

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