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.ts 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // @ts-expect-error
  2. import { jitsiLocalStorage } from '@jitsi/js-utils';
  3. import { escape } from 'lodash-es';
  4. import { APP_WILL_MOUNT } from '../app/actionTypes';
  5. import PersistenceRegistry from '../redux/PersistenceRegistry';
  6. import ReducerRegistry from '../redux/ReducerRegistry';
  7. import { assignIfDefined } from '../util/helpers';
  8. import { SETTINGS_UPDATED } from './actionTypes';
  9. /**
  10. * The default/initial redux state of the feature {@code base/settings}.
  11. *
  12. * @type Object
  13. */
  14. const DEFAULT_STATE: ISettingsState = {
  15. audioOutputDeviceId: undefined,
  16. avatarURL: undefined,
  17. cameraDeviceId: undefined,
  18. disableCallIntegration: undefined,
  19. disableCrashReporting: undefined,
  20. disableP2P: undefined,
  21. disableSelfView: false,
  22. displayName: undefined,
  23. email: undefined,
  24. localFlipX: true,
  25. maxStageParticipants: 1,
  26. micDeviceId: undefined,
  27. serverURL: undefined,
  28. hideShareAudioHelper: false,
  29. soundsIncomingMessage: true,
  30. soundsParticipantJoined: true,
  31. soundsParticipantKnocking: true,
  32. soundsParticipantLeft: true,
  33. soundsTalkWhileMuted: true,
  34. soundsReactions: true,
  35. startAudioOnly: false,
  36. startCarMode: false,
  37. startWithAudioMuted: false,
  38. startWithVideoMuted: false,
  39. userSelectedAudioOutputDeviceId: undefined,
  40. userSelectedCameraDeviceId: undefined,
  41. userSelectedMicDeviceId: undefined,
  42. userSelectedAudioOutputDeviceLabel: undefined,
  43. userSelectedCameraDeviceLabel: undefined,
  44. userSelectedNotifications: {
  45. 'notify.chatMessages': true
  46. },
  47. userSelectedMicDeviceLabel: undefined,
  48. userSelectedSkipPrejoin: undefined
  49. };
  50. export interface ISettingsState {
  51. audioOutputDeviceId?: string;
  52. audioSettingsVisible?: boolean;
  53. avatarURL?: string;
  54. cameraDeviceId?: string | boolean;
  55. disableCallIntegration?: boolean;
  56. disableCrashReporting?: boolean;
  57. disableP2P?: boolean;
  58. disableSelfView?: boolean;
  59. displayName?: string;
  60. email?: string;
  61. hideShareAudioHelper?: boolean;
  62. localFlipX?: boolean;
  63. maxStageParticipants?: number;
  64. micDeviceId?: string | boolean;
  65. serverURL?: string;
  66. soundsIncomingMessage?: boolean;
  67. soundsParticipantJoined?: boolean;
  68. soundsParticipantKnocking?: boolean;
  69. soundsParticipantLeft?: boolean;
  70. soundsReactions?: boolean;
  71. soundsTalkWhileMuted?: boolean;
  72. startAudioOnly?: boolean;
  73. startCarMode?: boolean;
  74. startWithAudioMuted?: boolean;
  75. startWithVideoMuted?: boolean;
  76. userSelectedAudioOutputDeviceId?: string;
  77. userSelectedAudioOutputDeviceLabel?: string;
  78. userSelectedCameraDeviceId?: string;
  79. userSelectedCameraDeviceLabel?: string;
  80. userSelectedMicDeviceId?: string;
  81. userSelectedMicDeviceLabel?: string;
  82. userSelectedNotifications?: {
  83. [key: string]: boolean;
  84. };
  85. userSelectedSkipPrejoin?: boolean;
  86. videoSettingsVisible?: boolean;
  87. visible?: boolean;
  88. }
  89. const STORE_NAME = 'features/base/settings';
  90. /**
  91. * Sets up the persistence of the feature {@code base/settings}.
  92. */
  93. const filterSubtree: ISettingsState = {};
  94. // start with the default state
  95. Object.keys(DEFAULT_STATE).forEach(key => {
  96. const key1 = key as keyof typeof filterSubtree;
  97. // @ts-ignore
  98. filterSubtree[key1] = true;
  99. });
  100. // we want to filter these props, to not be stored as they represent
  101. // what is currently opened/used as devices
  102. // @ts-ignore
  103. filterSubtree.audioOutputDeviceId = false;
  104. filterSubtree.cameraDeviceId = false;
  105. filterSubtree.micDeviceId = false;
  106. PersistenceRegistry.register(STORE_NAME, filterSubtree, DEFAULT_STATE);
  107. ReducerRegistry.register<ISettingsState>(STORE_NAME, (state = DEFAULT_STATE, action): ISettingsState => {
  108. switch (action.type) {
  109. case APP_WILL_MOUNT:
  110. return _initSettings(state);
  111. case SETTINGS_UPDATED:
  112. return {
  113. ...state,
  114. ...action.settings
  115. };
  116. }
  117. return state;
  118. });
  119. /**
  120. * Inits the settings object based on what information we have available.
  121. * Info taken into consideration:
  122. * - Old Settings.js style data.
  123. *
  124. * @private
  125. * @param {ISettingsState} featureState - The current state of the feature.
  126. * @returns {Object}
  127. */
  128. function _initSettings(featureState: ISettingsState) {
  129. let settings = featureState;
  130. // Old Settings.js values
  131. // FIXME: jibri uses old settings.js local storage values to set its display
  132. // name and email. Provide another way for jibri to set these values, update
  133. // jibri, and remove the old settings.js values.
  134. const savedDisplayName = jitsiLocalStorage.getItem('displayname');
  135. const savedEmail = jitsiLocalStorage.getItem('email');
  136. // The helper _.escape will convert null to an empty strings. The empty
  137. // string will be saved in settings. On app re-load, because an empty string
  138. // is a defined value, it will override any value found in local storage.
  139. // The workaround is sidestepping _.escape when the value is not set in
  140. // local storage.
  141. const displayName = savedDisplayName === null ? undefined : escape(savedDisplayName);
  142. const email = savedEmail === null ? undefined : escape(savedEmail);
  143. settings = assignIfDefined({
  144. displayName,
  145. email
  146. }, settings);
  147. return settings;
  148. }