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.

JitsiMeetLogStorage.ts 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { IStore } from '../../app/types';
  2. import JitsiMeetJS from '../../base/lib-jitsi-meet';
  3. import RTCStats from '../../rtcstats/RTCStats';
  4. import { isRTCStatsEnabled } from '../../rtcstats/functions';
  5. /**
  6. * Implements log storage interface from the @jitsi/logger lib, as it stands
  7. * now it only sends logs to the rtcstats server in case it is enabled.
  8. */
  9. export default class JitsiMeetLogStorage {
  10. getState: IStore['getState'];
  11. /**
  12. * Creates new <tt>JitsiMeetLogStorage</tt>.
  13. *
  14. * @param {Function} getState - The Redux store's {@code getState} method.
  15. */
  16. constructor(getState: IStore['getState']) {
  17. /**
  18. * The Redux store's {@code getState} method.
  19. *
  20. * @type {Function}
  21. */
  22. this.getState = getState;
  23. }
  24. /**
  25. * The JitsiMeetLogStorage is ready we can use the rtcstats trace to send logs
  26. * to the rtcstats server.
  27. *
  28. * @returns {boolean} <tt>true</tt> when this storage is ready or
  29. * <tt>false</tt> otherwise.
  30. */
  31. isReady() {
  32. return JitsiMeetJS.rtcstats.isTraceAvailable();
  33. }
  34. /**
  35. * Checks whether rtcstats logs storage is enabled.
  36. *
  37. * @returns {boolean} <tt>true</tt> when this storage can store logs to
  38. * rtcstats, <tt>false</tt> otherwise.
  39. */
  40. canStoreLogsRtcstats() {
  41. const config = this.getState()['features/base/config'];
  42. // RTCStats can run without sending app logs to the server.
  43. // Be mindful that there exists another LogStorage instance withing lib-jitsi-meet,
  44. // that is used to send logs generated there.
  45. return config?.analytics?.rtcstatsStoreLogs && isRTCStatsEnabled(this.getState());
  46. }
  47. /**
  48. * Called by the <tt>LogCollector</tt> to store a series of log lines into
  49. * batch.
  50. *
  51. * @param {Array<string|Object>} logEntries - An array containing strings
  52. * representing log lines or aggregated lines objects.
  53. * @returns {void}
  54. */
  55. storeLogs(logEntries: Array<string | any>) {
  56. if (this.canStoreLogsRtcstats()) {
  57. RTCStats.sendLogs(logEntries);
  58. }
  59. }
  60. }