Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

JitsiMeetLogStorage.ts 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // @ts-ignore
  2. import { getCurrentConference } from '../conference';
  3. /**
  4. * Implements log storage interface from the @jitsi/logger lib. Captured
  5. * logs are sent to CallStats.
  6. */
  7. export default class JitsiMeetLogStorage {
  8. counter: number;
  9. getState: Function;
  10. /**
  11. * Creates new <tt>JitsiMeetLogStorage</tt>.
  12. *
  13. * @param {Function} getState - The Redux store's {@code getState} method.
  14. */
  15. constructor(getState: Function) {
  16. /**
  17. * Counts each log entry, increases on every batch log entry stored.
  18. *
  19. * @type {number}
  20. */
  21. this.counter = 1;
  22. /**
  23. * The Redux store's {@code getState} method.
  24. *
  25. * @type {Function}
  26. */
  27. this.getState = getState;
  28. }
  29. /**
  30. * The JitsiMeetLogStorage is ready when the CallStats are started and
  31. * before refactoring the code it was after the conference has been joined.
  32. * A conference is considered joined when the 'conference' field is defined
  33. * in the base/conference state.
  34. *
  35. * @returns {boolean} <tt>true</tt> when this storage is ready or
  36. * <tt>false</tt> otherwise.
  37. */
  38. isReady() {
  39. const { conference } = this.getState()['features/base/conference'];
  40. return Boolean(conference);
  41. }
  42. /**
  43. * Called by the <tt>LogCollector</tt> to store a series of log lines into
  44. * batch.
  45. *
  46. * @param {Array<string|Object>} logEntries - An array containing strings
  47. * representing log lines or aggregated lines objects.
  48. * @returns {void}
  49. */
  50. storeLogs(logEntries: Array<string|any>) {
  51. const conference = getCurrentConference(this.getState());
  52. if (!conference || !conference.isCallstatsEnabled()) {
  53. // Discard the logs if CallStats is not enabled.
  54. return;
  55. }
  56. let logMessage = `{"log${this.counter}":"\n`;
  57. for (let i = 0, len = logEntries.length; i < len; i++) {
  58. const logEntry = logEntries[i];
  59. if (logEntry.timestamp) {
  60. logMessage += `${logEntry.timestamp} `;
  61. }
  62. if (logEntry.count > 1) {
  63. logMessage += `(${logEntry.count}) `;
  64. }
  65. logMessage += `${logEntry.text}\n`;
  66. }
  67. logMessage += '"}';
  68. this.counter += 1;
  69. // Try catch was used, because there are many variables
  70. // on the way that could be uninitialized if the storeLogs
  71. // attempt would be made very early (which is unlikely)
  72. try {
  73. conference.sendApplicationLog(logMessage);
  74. } catch (error) {
  75. // NOTE console is intentional here
  76. console.error(
  77. `Failed to store the logs, msg length: ${logMessage.length}`
  78. + `error: ${JSON.stringify(error)}`);
  79. }
  80. }
  81. }