Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

JitsiMeetLogStorage.ts 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import RTCStats from '../../rtcstats/RTCStats';
  2. import { canSendRtcstatsData } from '../../rtcstats/functions';
  3. import { getCurrentConference } from '../conference/functions';
  4. /**
  5. * Implements log storage interface from the @jitsi/logger lib. Captured
  6. * logs are sent to CallStats.
  7. */
  8. export default class JitsiMeetLogStorage {
  9. counter: number;
  10. getState: Function;
  11. /**
  12. * Creates new <tt>JitsiMeetLogStorage</tt>.
  13. *
  14. * @param {Function} getState - The Redux store's {@code getState} method.
  15. */
  16. constructor(getState: Function) {
  17. /**
  18. * Counts each log entry, increases on every batch log entry stored.
  19. *
  20. * @type {number}
  21. */
  22. this.counter = 1;
  23. /**
  24. * The Redux store's {@code getState} method.
  25. *
  26. * @type {Function}
  27. */
  28. this.getState = getState;
  29. }
  30. /**
  31. * The JitsiMeetLogStorage is ready when the CallStats are started and
  32. * before refactoring the code it was after the conference has been joined.
  33. * A conference is considered joined when the 'conference' field is defined
  34. * in the base/conference state.
  35. *
  36. * @returns {boolean} <tt>true</tt> when this storage is ready or
  37. * <tt>false</tt> otherwise.
  38. */
  39. isReady() {
  40. const { conference } = this.getState()['features/base/conference'];
  41. return Boolean(conference);
  42. }
  43. /**
  44. * Checks whether rtcstats logs storage is enabled.
  45. *
  46. * @returns {boolean} <tt>true</tt> when this storage can store logs to
  47. * rtcstats, <tt>false</tt> otherwise.
  48. */
  49. canStoreLogsRtcstats() {
  50. const config = this.getState()['features/base/config'];
  51. // Saving the logs in RTCStats is a new feature and so there is no prior behavior that needs to be maintained.
  52. // That said, this is still experimental and needs to be rolled out gradually so we want this to be off by
  53. // default.
  54. return config?.analytics?.rtcstatsStoreLogs && canSendRtcstatsData(this.getState());
  55. }
  56. /**
  57. * Called by the <tt>LogCollector</tt> to store a series of log lines into
  58. * batch.
  59. *
  60. * @param {Array<string|Object>} logEntries - An array containing strings
  61. * representing log lines or aggregated lines objects.
  62. * @returns {void}
  63. */
  64. storeLogs(logEntries: Array<string | any>) {
  65. // XXX the config.callStatsApplicationLogsDisabled controls whether or not the logs will be sent to callstats.
  66. // this is done in LJM
  67. this.storeLogsCallstats(logEntries);
  68. if (this.canStoreLogsRtcstats()) {
  69. RTCStats.sendLogs(logEntries);
  70. }
  71. }
  72. /**
  73. * Store the console logs in callstats (if callstats is enabled).
  74. *
  75. * @param {Array<string|any>} logEntries - The log entries to send to the rtcstats server.
  76. * @returns {void}
  77. */
  78. storeLogsCallstats(logEntries: Array<string | any>) {
  79. const conference = getCurrentConference(this.getState());
  80. if (!conference || !conference.isCallstatsEnabled()) {
  81. // Discard the logs if CallStats is not enabled.
  82. return;
  83. }
  84. let logMessage = `{"log${this.counter}":"\n`;
  85. for (let i = 0, len = logEntries.length; i < len; i++) {
  86. const logEntry = logEntries[i];
  87. if (logEntry.timestamp) {
  88. logMessage += `${logEntry.timestamp} `;
  89. }
  90. if (logEntry.count > 1) {
  91. logMessage += `(${logEntry.count}) `;
  92. }
  93. logMessage += `${logEntry.text}\n`;
  94. }
  95. logMessage += '"}';
  96. this.counter += 1;
  97. // Try catch was used, because there are many variables
  98. // on the way that could be uninitialized if the storeLogs
  99. // attempt would be made very early (which is unlikely)
  100. try {
  101. conference.sendApplicationLog(logMessage);
  102. } catch (error) {
  103. // NOTE console is intentional here
  104. console.error(
  105. `Failed to store the logs, msg length: ${logMessage.length}`
  106. + `error: ${JSON.stringify(error)}`);
  107. }
  108. }
  109. }