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

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