您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

JitsiMeetLogStorage.js 2.7KB

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