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.

AbstractHandler.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Abstract implementation of analytics handler
  3. */
  4. export default class AbstractHandler {
  5. /**
  6. * Creates new instance.
  7. */
  8. constructor() {
  9. this._enabled = false;
  10. this._ignoredEvents
  11. = [ 'e2e_rtt', 'rtp.stats', 'rtt.by.region', 'available.device',
  12. 'stream.switch.delay', 'ice.state.changed', 'ice.duration' ];
  13. }
  14. /**
  15. * Extracts a name for the event from the event properties.
  16. *
  17. * @param {Object} event - The analytics event.
  18. * @returns {string} - The extracted name.
  19. */
  20. _extractName(event) {
  21. // Page events have a single 'name' field.
  22. if (event.type === 'page') {
  23. return event.name;
  24. }
  25. const {
  26. action,
  27. actionSubject,
  28. source
  29. } = event;
  30. // All events have action, actionSubject, and source fields. All
  31. // three fields are required, and often jitsi-meet and
  32. // lib-jitsi-meet use the same value when separate values are not
  33. // necessary (i.e. event.action == event.actionSubject).
  34. // Here we concatenate these three fields, but avoid adding the same
  35. // value twice, because it would only make the event's name harder
  36. // to read.
  37. let name = action;
  38. if (actionSubject && actionSubject !== action) {
  39. name = `${actionSubject}.${action}`;
  40. }
  41. if (source && source !== action) {
  42. name = `${source}.${name}`;
  43. }
  44. return name;
  45. }
  46. /**
  47. * Checks if an event should be ignored or not.
  48. *
  49. * @param {Object} event - The event.
  50. * @returns {boolean}
  51. */
  52. _shouldIgnore(event) {
  53. if (!event || !this._enabled) {
  54. return true;
  55. }
  56. // Temporary removing some of the events that are too noisy.
  57. return this._ignoredEvents.indexOf(event.action) !== -1;
  58. }
  59. }