您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 { TOGGLE_DOCUMENT_EDITING } from '../etherpad/actionTypes';
  16. import { selectParticipantInLargeVideo } from './actions';
  17. import logger from './logger';
  18. import './subscriber';
  19. /**
  20. * Middleware that catches actions related to participants and tracks and
  21. * dispatches an action to select a participant depicted by LargeVideo.
  22. *
  23. * @param {Store} store - Redux store.
  24. * @returns {Function}
  25. */
  26. MiddlewareRegistry.register(store => next => action => {
  27. const result = next(action);
  28. switch (action.type) {
  29. case DOMINANT_SPEAKER_CHANGED: {
  30. const state = store.getState();
  31. const localParticipant = getLocalParticipant(state);
  32. if (isTestModeEnabled(state)) {
  33. logger.info(`Dominant speaker changed event for: ${action.participant.id}`);
  34. }
  35. if (localParticipant && localParticipant.id !== action.participant.id) {
  36. store.dispatch(selectParticipantInLargeVideo());
  37. }
  38. break;
  39. }
  40. case PARTICIPANT_JOINED:
  41. case PARTICIPANT_LEFT:
  42. case PIN_PARTICIPANT:
  43. case TOGGLE_DOCUMENT_EDITING:
  44. case TRACK_ADDED:
  45. case TRACK_REMOVED:
  46. store.dispatch(selectParticipantInLargeVideo());
  47. break;
  48. }
  49. return result;
  50. });