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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 { isTestModeEnabled } from '../base/testing';
  12. import {
  13. getTrackByJitsiTrack,
  14. TRACK_ADDED,
  15. TRACK_REMOVED,
  16. TRACK_UPDATED
  17. } from '../base/tracks';
  18. import { selectParticipant, selectParticipantInLargeVideo } from './actions';
  19. import logger from './logger';
  20. import './subscriber';
  21. /**
  22. * Middleware that catches actions related to participants and tracks and
  23. * dispatches an action to select a participant depicted by LargeVideo.
  24. *
  25. * @param {Store} store - Redux store.
  26. * @returns {Function}
  27. */
  28. MiddlewareRegistry.register(store => next => action => {
  29. const result = next(action);
  30. switch (action.type) {
  31. case DOMINANT_SPEAKER_CHANGED: {
  32. const state = store.getState();
  33. const localParticipant = getLocalParticipant(state);
  34. if (isTestModeEnabled(state)) {
  35. logger.info(`Dominant speaker changed event for: ${action.participant.id}`);
  36. }
  37. if (localParticipant && localParticipant.id !== action.participant.id) {
  38. store.dispatch(selectParticipantInLargeVideo());
  39. }
  40. break;
  41. }
  42. case PARTICIPANT_JOINED:
  43. case PARTICIPANT_LEFT:
  44. case PIN_PARTICIPANT:
  45. case TRACK_ADDED:
  46. case TRACK_REMOVED:
  47. store.dispatch(selectParticipantInLargeVideo());
  48. break;
  49. case CONFERENCE_JOINED:
  50. // Ensure a participant is selected on conference join. This addresses
  51. // the case where video tracks were received before CONFERENCE_JOINED
  52. // fired; without the conference selection may not happen.
  53. store.dispatch(selectParticipant());
  54. break;
  55. case TRACK_UPDATED:
  56. // In order to minimize re-calculations, we need to select participant
  57. // only if the videoType of the current participant rendered in
  58. // LargeVideo has changed.
  59. if ('videoType' in action.track) {
  60. const state = store.getState();
  61. const track
  62. = getTrackByJitsiTrack(
  63. state['features/base/tracks'],
  64. action.track.jitsiTrack);
  65. const participantId = state['features/large-video'].participantId;
  66. (track.participantId === participantId)
  67. && store.dispatch(selectParticipant());
  68. }
  69. break;
  70. }
  71. return result;
  72. });