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

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