import { IStore } from '../../app/types';
import JitsiMeetJS from '../../base/lib-jitsi-meet';
import RTCStats from '../../rtcstats/RTCStats';
import { isRTCStatsEnabled } from '../../rtcstats/functions';
/**
* Implements log storage interface from the @jitsi/logger lib, as it stands
* now it only sends logs to the rtcstats server in case it is enabled.
*/
export default class JitsiMeetLogStorage {
getState: IStore['getState'];
/**
* Creates new JitsiMeetLogStorage.
*
* @param {Function} getState - The Redux store's {@code getState} method.
*/
constructor(getState: IStore['getState']) {
/**
* The Redux store's {@code getState} method.
*
* @type {Function}
*/
this.getState = getState;
}
/**
* The JitsiMeetLogStorage is ready we can use the rtcstats trace to send logs
* to the rtcstats server.
*
* @returns {boolean} true when this storage is ready or
* false otherwise.
*/
isReady() {
return JitsiMeetJS.rtcstats.isTraceAvailable();
}
/**
* Checks whether rtcstats logs storage is enabled.
*
* @returns {boolean} true when this storage can store logs to
* rtcstats, false otherwise.
*/
canStoreLogsRtcstats() {
const config = this.getState()['features/base/config'];
// RTCStats can run without sending app logs to the server.
// Be mindful that there exists another LogStorage instance withing lib-jitsi-meet,
// that is used to send logs generated there.
return config?.analytics?.rtcstatsStoreLogs && isRTCStatsEnabled(this.getState());
}
/**
* Called by the LogCollector to store a series of log lines into
* batch.
*
* @param {Array} logEntries - An array containing strings
* representing log lines or aggregated lines objects.
* @returns {void}
*/
storeLogs(logEntries: Array) {
if (this.canStoreLogsRtcstats()) {
RTCStats.sendLogs(logEntries);
}
}
}