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.js 2.7KB

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