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 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import _ from 'lodash';
  2. import ReducerRegistry from '../redux/ReducerRegistry';
  3. import { equals, set } from '../redux/functions';
  4. import { SET_LOG_COLLECTOR, SET_LOGGING_CONFIG } from './actionTypes';
  5. const DEFAULT_LOGGING_CONFIG = {
  6. // default log level for the app and lib-jitsi-meet
  7. defaultLogLevel: 'trace' as LogLevel,
  8. // Option to disable LogCollector (which stores the logs on CallStats)
  9. // disableLogCollector: true,
  10. loggers: {
  11. // The following are too verbose in their logging with the
  12. // {@link #defaultLogLevel}:
  13. 'modules/RTC/TraceablePeerConnection.js': 'info' as LogLevel,
  14. 'modules/statistics/CallStats.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?: Object;
  55. }
  56. ReducerRegistry.register(
  57. 'features/base/logging',
  58. (state: ILoggingState = DEFAULT_STATE, action) => {
  59. switch (action.type) {
  60. case SET_LOGGING_CONFIG:
  61. return _setLoggingConfig(state, action);
  62. case SET_LOG_COLLECTOR: {
  63. return _setLogCollector(state, action);
  64. }
  65. default:
  66. return state;
  67. }
  68. });
  69. /**
  70. * Reduces a specific Redux action SET_LOGGING_CONFIG of the feature
  71. * base/logging.
  72. *
  73. * @param {Object} state - The Redux state of the feature base/logging.
  74. * @param {Action} action - The Redux action SET_LOGGING_CONFIG to reduce.
  75. * @private
  76. * @returns {Object} The new state of the feature base/logging after the
  77. * reduction of the specified action.
  78. */
  79. function _setLoggingConfig(state: ILoggingState, action: any) {
  80. const newConfig = _.merge({}, DEFAULT_STATE.config, action.config);
  81. if (equals(state.config, newConfig)) {
  82. return state;
  83. }
  84. return {
  85. ...state,
  86. config: newConfig
  87. };
  88. }
  89. /**
  90. * Reduces a specific Redux action SET_LOG_COLLECTOR of the feature
  91. * base/logging.
  92. *
  93. * @param {Object} state - The Redux state of the feature base/logging.
  94. * @param {Action} action - The Redux action SET_LOG_COLLECTOR to reduce.
  95. * @private
  96. * @returns {Object} The new state of the feature base/logging after the
  97. * reduction of the specified action.
  98. */
  99. function _setLogCollector(state: ILoggingState, action: any) {
  100. return set(state, 'logCollector', action.logCollector);
  101. }