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

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