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

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