Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

middleware.js 1.8KB

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