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.ts 1.2KB

123456789101112131415161718192021222324252627
  1. import { createRejoinedEvent } from '../analytics/AnalyticsEvents';
  2. import { sendAnalytics } from '../analytics/functions';
  3. import StateListenerRegistry from '../base/redux/StateListenerRegistry';
  4. StateListenerRegistry.register(
  5. /* selector */ state => {
  6. const recentList = state['features/recent-list'];
  7. // Return the most recent conference entry
  8. return recentList?.length && recentList[recentList.length - 1];
  9. },
  10. // eslint-disable-next-line no-empty-pattern
  11. /* listener */ (newMostRecent, { }, prevMostRecent) => {
  12. if (prevMostRecent && newMostRecent) {
  13. // Send the rejoined event just before the duration is reset on the most recent entry
  14. if (prevMostRecent.conference === newMostRecent.conference && newMostRecent.duration === 0) {
  15. sendAnalytics(
  16. createRejoinedEvent({
  17. lastConferenceDuration: prevMostRecent.duration / 1000,
  18. timeSinceLeft: (Date.now() - (prevMostRecent.date + prevMostRecent.duration)) / 1000,
  19. url: prevMostRecent.conference
  20. })
  21. );
  22. }
  23. }
  24. });