您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

reducer.ts 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // @ts-ignore
  2. import { jitsiLocalStorage } from '@jitsi/js-utils';
  3. import _ from 'lodash';
  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 | boolean;
  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. filterSubtree.audioOutputDeviceId = false;
  103. filterSubtree.cameraDeviceId = false;
  104. filterSubtree.micDeviceId = false;
  105. PersistenceRegistry.register(STORE_NAME, filterSubtree, DEFAULT_STATE);
  106. ReducerRegistry.register<ISettingsState>(STORE_NAME, (state = DEFAULT_STATE, action): ISettingsState => {
  107. switch (action.type) {
  108. case APP_WILL_MOUNT:
  109. return _initSettings(state);
  110. case SETTINGS_UPDATED:
  111. return {
  112. ...state,
  113. ...action.settings
  114. };
  115. }
  116. return state;
  117. });
  118. /**
  119. * Inits the settings object based on what information we have available.
  120. * Info taken into consideration:
  121. * - Old Settings.js style data.
  122. *
  123. * @private
  124. * @param {ISettingsState} featureState - The current state of the feature.
  125. * @returns {Object}
  126. */
  127. function _initSettings(featureState: ISettingsState) {
  128. let settings = featureState;
  129. // Old Settings.js values
  130. // FIXME: jibri uses old settings.js local storage values to set its display
  131. // name and email. Provide another way for jibri to set these values, update
  132. // jibri, and remove the old settings.js values.
  133. const savedDisplayName = jitsiLocalStorage.getItem('displayname');
  134. const savedEmail = jitsiLocalStorage.getItem('email');
  135. // The helper _.escape will convert null to an empty strings. The empty
  136. // string will be saved in settings. On app re-load, because an empty string
  137. // is a defined value, it will override any value found in local storage.
  138. // The workaround is sidestepping _.escape when the value is not set in
  139. // local storage.
  140. const displayName = savedDisplayName === null ? undefined : _.escape(savedDisplayName);
  141. const email = savedEmail === null ? undefined : _.escape(savedEmail);
  142. settings = assignIfDefined({
  143. displayName,
  144. email
  145. }, settings);
  146. return settings;
  147. }