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

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