Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

JitsiMeetLogStorage.ts 4.1KB

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