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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // @flow
  2. import {
  3. DOMINANT_SPEAKER_CHANGED,
  4. PARTICIPANT_JOINED,
  5. PARTICIPANT_LEFT,
  6. PIN_PARTICIPANT,
  7. getLocalParticipant
  8. } from '../base/participants';
  9. import { MiddlewareRegistry } from '../base/redux';
  10. import { isTestModeEnabled } from '../base/testing';
  11. import {
  12. TRACK_ADDED,
  13. TRACK_REMOVED
  14. } from '../base/tracks';
  15. import { selectParticipantInLargeVideo } from './actions';
  16. import logger from './logger';
  17. import './subscriber';
  18. /**
  19. * Middleware that catches actions related to participants and tracks and
  20. * dispatches an action to select a participant depicted by LargeVideo.
  21. *
  22. * @param {Store} store - Redux store.
  23. * @returns {Function}
  24. */
  25. MiddlewareRegistry.register(store => next => action => {
  26. const result = next(action);
  27. switch (action.type) {
  28. case DOMINANT_SPEAKER_CHANGED: {
  29. const state = store.getState();
  30. const localParticipant = getLocalParticipant(state);
  31. if (isTestModeEnabled(state)) {
  32. logger.info(`Dominant speaker changed event for: ${action.participant.id}`);
  33. }
  34. if (localParticipant && localParticipant.id !== action.participant.id) {
  35. store.dispatch(selectParticipantInLargeVideo());
  36. }
  37. break;
  38. }
  39. case PARTICIPANT_JOINED:
  40. case PARTICIPANT_LEFT:
  41. case PIN_PARTICIPANT:
  42. case TRACK_ADDED:
  43. case TRACK_REMOVED:
  44. store.dispatch(selectParticipantInLargeVideo());
  45. break;
  46. }
  47. return result;
  48. });