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 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * Abstract implementation of analytics handler
  3. */
  4. export default class AbstractHandler {
  5. /**
  6. * Creates new instance.
  7. *
  8. * @param {Object} options - Optional parameters.
  9. */
  10. constructor(options = {}) {
  11. this._enabled = false;
  12. this._whiteListedEvents = options.whiteListedEvents;
  13. // FIXME:
  14. // Keeping the list with the very noisy events so that we don't flood with events whoever hasn't configured
  15. // white/black lists yet. We need to solve this issue properly by either making these events not so noisy or
  16. // by removing them completely from the code.
  17. this._blackListedEvents = [
  18. ...(options.blackListedEvents || []), // eslint-disable-line no-extra-parens
  19. 'e2e_rtt', 'rtp.stats', 'rtt.by.region', 'available.device', 'stream.switch.delay', 'ice.state.changed',
  20. 'ice.duration', 'peer.conn.status.duration'
  21. ];
  22. }
  23. /**
  24. * Extracts a name for the event from the event properties.
  25. *
  26. * @param {Object} event - The analytics event.
  27. * @returns {string} - The extracted name.
  28. */
  29. _extractName(event) {
  30. // Page events have a single 'name' field.
  31. if (event.type === 'page') {
  32. return event.name;
  33. }
  34. const {
  35. action,
  36. actionSubject,
  37. source
  38. } = event;
  39. // All events have action, actionSubject, and source fields. All
  40. // three fields are required, and often jitsi-meet and
  41. // lib-jitsi-meet use the same value when separate values are not
  42. // necessary (i.e. event.action == event.actionSubject).
  43. // Here we concatenate these three fields, but avoid adding the same
  44. // value twice, because it would only make the event's name harder
  45. // to read.
  46. let name = action;
  47. if (actionSubject && actionSubject !== action) {
  48. name = `${actionSubject}.${action}`;
  49. }
  50. if (source && source !== action) {
  51. name = `${source}.${name}`;
  52. }
  53. return name;
  54. }
  55. /**
  56. * Checks if an event should be ignored or not.
  57. *
  58. * @param {Object} event - The event.
  59. * @returns {boolean}
  60. */
  61. _shouldIgnore(event) {
  62. if (!event || !this._enabled) {
  63. return true;
  64. }
  65. const name = this._extractName(event);
  66. if (Array.isArray(this._whiteListedEvents)) {
  67. return this._whiteListedEvents.indexOf(name) === -1;
  68. }
  69. if (Array.isArray(this._blackListedEvents)) {
  70. return this._blackListedEvents.indexOf(name) !== -1;
  71. }
  72. return false;
  73. }
  74. }