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

middleware.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // @flow
  2. import {
  3. DOMINANT_SPEAKER_CHANGED,
  4. PARTICIPANT_JOINED,
  5. PARTICIPANT_LEFT,
  6. PIN_PARTICIPANT
  7. } from '../base/participants';
  8. import { MiddlewareRegistry } from '../base/redux';
  9. import {
  10. getTrackByJitsiTrack,
  11. TRACK_ADDED,
  12. TRACK_REMOVED,
  13. TRACK_UPDATED
  14. } from '../base/tracks';
  15. import { selectParticipant, selectParticipantInLargeVideo } from './actions';
  16. /**
  17. * Middleware that catches actions related to participants and tracks and
  18. * dispatches an action to select a participant depicted by LargeVideo.
  19. *
  20. * @param {Store} store - Redux store.
  21. * @returns {Function}
  22. */
  23. MiddlewareRegistry.register(store => next => action => {
  24. const result = next(action);
  25. switch (action.type) {
  26. case DOMINANT_SPEAKER_CHANGED:
  27. case PARTICIPANT_JOINED:
  28. case PARTICIPANT_LEFT:
  29. case PIN_PARTICIPANT:
  30. case TRACK_ADDED:
  31. case TRACK_REMOVED:
  32. store.dispatch(selectParticipantInLargeVideo());
  33. break;
  34. case TRACK_UPDATED:
  35. // In order to minimize re-calculations, we need to select participant
  36. // only if the videoType of the current participant rendered in
  37. // LargeVideo has changed.
  38. if ('videoType' in action.track) {
  39. const state = store.getState();
  40. const track
  41. = getTrackByJitsiTrack(
  42. state['features/base/tracks'],
  43. action.track.jitsiTrack);
  44. const participantId = state['features/large-video'].participantId;
  45. (track.participantId === participantId)
  46. && store.dispatch(selectParticipant());
  47. }
  48. break;
  49. }
  50. return result;
  51. });