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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. 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 localParticipant = getLocalParticipant(store.getState());
  31. if (localParticipant && localParticipant.id !== action.participant.id) {
  32. store.dispatch(selectParticipantInLargeVideo());
  33. }
  34. break;
  35. }
  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 CONFERENCE_JOINED:
  44. // Ensure a participant is selected on conference join. This addresses
  45. // the case where video tracks were received before CONFERENCE_JOINED
  46. // fired; without the conference selection may not happen.
  47. store.dispatch(selectParticipant());
  48. break;
  49. case TRACK_UPDATED:
  50. // In order to minimize re-calculations, we need to select participant
  51. // only if the videoType of the current participant rendered in
  52. // LargeVideo has changed.
  53. if ('videoType' in action.track) {
  54. const state = store.getState();
  55. const track
  56. = getTrackByJitsiTrack(
  57. state['features/base/tracks'],
  58. action.track.jitsiTrack);
  59. const participantId = state['features/large-video'].participantId;
  60. (track.participantId === participantId)
  61. && store.dispatch(selectParticipant());
  62. }
  63. break;
  64. }
  65. return result;
  66. });