"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7553/react/features/base/logging/reducer.ts" (27 Sep 2023, 3449 Bytes) of package /linux/misc/jitsi-meet-7553.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

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