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.

middleware.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { sendAnalytics, createVpaasConferenceJoinedEvent } from '../analytics';
  2. import { CONFERENCE_JOINED } from '../base/conference/actionTypes';
  3. import { PARTICIPANT_JOINED } from '../base/participants/actionTypes';
  4. import { MiddlewareRegistry } from '../base/redux';
  5. import { SET_BILLING_ID } from './actionTypes';
  6. import { countEndpoint } from './actions';
  7. import { isVpaasMeeting, extractVpaasTenantFromPath, setBillingId } from './functions';
  8. /**
  9. * The redux middleware for billing counter.
  10. *
  11. * @param {Store} store - The redux store.
  12. * @returns {Function}
  13. */
  14. MiddlewareRegistry.register(store => next => async action => {
  15. switch (action.type) {
  16. case CONFERENCE_JOINED: {
  17. _maybeTrackVpaasConferenceJoin(store.getState());
  18. break;
  19. }
  20. case SET_BILLING_ID: {
  21. setBillingId(action.value);
  22. break;
  23. }
  24. case PARTICIPANT_JOINED: {
  25. const shouldCount = !store.getState()['features/billing-counter'].endpointCounted
  26. && !action.participant.local;
  27. if (shouldCount) {
  28. store.dispatch(countEndpoint());
  29. }
  30. break;
  31. }
  32. }
  33. return next(action);
  34. });
  35. /**
  36. * Tracks the conference join event if the meeting is a vpaas one.
  37. *
  38. * @param {Store} state - The app state.
  39. * @returns {Function}
  40. */
  41. function _maybeTrackVpaasConferenceJoin(state) {
  42. if (isVpaasMeeting(state)) {
  43. sendAnalytics(createVpaasConferenceJoinedEvent(
  44. extractVpaasTenantFromPath(
  45. state['features/base/connection'].locationURL.pathname)));
  46. }
  47. }