Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

reducer.ts 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import _ from 'lodash';
  2. import { AnyAction } from 'redux';
  3. import ReducerRegistry from '../redux/ReducerRegistry';
  4. import { equals, set } from '../redux/functions';
  5. import { SET_LOGGING_CONFIG, SET_LOG_COLLECTOR } from './actionTypes';
  6. const DEFAULT_LOGGING_CONFIG = {
  7. // default log level for the app and lib-jitsi-meet
  8. defaultLogLevel: 'trace' as LogLevel,
  9. // Option to disable LogCollector (which stores the logs)
  10. // disableLogCollector: true,
  11. loggers: {
  12. // The following are too verbose in their logging with the
  13. // {@link #defaultLogLevel}:
  14. 'modules/RTC/TraceablePeerConnection.js': 'info' as LogLevel,
  15. 'modules/xmpp/strophe.util.js': 'log' as LogLevel
  16. }
  17. };
  18. /**
  19. * The default/initial redux state of the feature base/logging.
  20. *
  21. * @type {{
  22. * config: Object
  23. * }}
  24. */
  25. const DEFAULT_STATE = {
  26. config: DEFAULT_LOGGING_CONFIG,
  27. /**
  28. * The log collector.
  29. */
  30. logCollector: undefined
  31. };
  32. // Reduce default verbosity on mobile, it kills performance.
  33. if (navigator.product === 'ReactNative') {
  34. const RN_LOGGERS = {
  35. 'modules/sdp/SDPUtil.js': 'info' as LogLevel,
  36. 'modules/xmpp/ChatRoom.js': 'warn' as LogLevel,
  37. 'modules/xmpp/JingleSessionPC.js': 'info' as LogLevel,
  38. 'modules/xmpp/strophe.jingle.js': 'info' as LogLevel
  39. };
  40. DEFAULT_STATE.config.loggers = {
  41. ...DEFAULT_LOGGING_CONFIG.loggers,
  42. ...RN_LOGGERS
  43. };
  44. }
  45. type LogLevel = 'trace' | 'log' | 'info' | 'warn' | 'error';
  46. export interface ILoggingState {
  47. config: {
  48. defaultLogLevel: LogLevel;
  49. disableLogCollector?: boolean;
  50. loggers: {
  51. [key: string]: LogLevel;
  52. };
  53. };
  54. logCollector?: {
  55. flush: () => void;
  56. start: () => void;
  57. stop: () => void;
  58. };
  59. }
  60. ReducerRegistry.register<ILoggingState>(
  61. 'features/base/logging',
  62. (state = DEFAULT_STATE, action): ILoggingState => {
  63. switch (action.type) {
  64. case SET_LOGGING_CONFIG:
  65. return _setLoggingConfig(state, action);
  66. case SET_LOG_COLLECTOR: {
  67. return _setLogCollector(state, action);
  68. }
  69. default:
  70. return state;
  71. }
  72. });
  73. /**
  74. * Reduces a specific Redux action SET_LOGGING_CONFIG of the feature
  75. * base/logging.
  76. *
  77. * @param {Object} state - The Redux state of the feature base/logging.
  78. * @param {Action} action - The Redux action SET_LOGGING_CONFIG to reduce.
  79. * @private
  80. * @returns {Object} The new state of the feature base/logging after the
  81. * reduction of the specified action.
  82. */
  83. function _setLoggingConfig(state: ILoggingState, action: AnyAction) {
  84. const newConfig = _.merge({}, DEFAULT_STATE.config, action.config);
  85. if (equals(state.config, newConfig)) {
  86. return state;
  87. }
  88. return {
  89. ...state,
  90. config: newConfig
  91. };
  92. }
  93. /**
  94. * Reduces a specific Redux action SET_LOG_COLLECTOR of the feature
  95. * base/logging.
  96. *
  97. * @param {Object} state - The Redux state of the feature base/logging.
  98. * @param {Action} action - The Redux action SET_LOG_COLLECTOR to reduce.
  99. * @private
  100. * @returns {Object} The new state of the feature base/logging after the
  101. * reduction of the specified action.
  102. */
  103. function _setLogCollector(state: ILoggingState, action: AnyAction) {
  104. return set(state, 'logCollector', action.logCollector);
  105. }