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 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // @flow
  2. import { CONFERENCE_JOINED } from '../base/conference';
  3. import {
  4. DOMINANT_SPEAKER_CHANGED,
  5. PARTICIPANT_JOINED,
  6. PARTICIPANT_LEFT,
  7. PIN_PARTICIPANT,
  8. getLocalParticipant
  9. } from '../base/participants';
  10. import { MiddlewareRegistry } from '../base/redux';
  11. import {
  12. getTrackByJitsiTrack,
  13. TRACK_ADDED,
  14. TRACK_REMOVED,
  15. TRACK_UPDATED
  16. } from '../base/tracks';
  17. import { selectParticipant, selectParticipantInLargeVideo } from './actions';
  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 localParticipant = getLocalParticipant(store.getState());
  30. if (localParticipant && localParticipant.id !== action.participant.id) {
  31. store.dispatch(selectParticipantInLargeVideo());
  32. }
  33. break;
  34. }
  35. case CONFERENCE_JOINED:
  36. case PARTICIPANT_JOINED:
  37. case PARTICIPANT_LEFT:
  38. case PIN_PARTICIPANT:
  39. case TRACK_ADDED:
  40. case TRACK_REMOVED:
  41. store.dispatch(selectParticipantInLargeVideo());
  42. break;
  43. case TRACK_UPDATED:
  44. // In order to minimize re-calculations, we need to select participant
  45. // only if the videoType of the current participant rendered in
  46. // LargeVideo has changed.
  47. if ('videoType' in action.track) {
  48. const state = store.getState();
  49. const track
  50. = getTrackByJitsiTrack(
  51. state['features/base/tracks'],
  52. action.track.jitsiTrack);
  53. const participantId = state['features/large-video'].participantId;
  54. (track.participantId === participantId)
  55. && store.dispatch(selectParticipant());
  56. }
  57. break;
  58. }
  59. return result;
  60. });