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.

functions.any.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // @flow
  2. import { setRemoteParticipants } from './actions';
  3. /**
  4. * Computes the reorderd list of the remote participants.
  5. *
  6. * @param {*} store - The redux store.
  7. * @returns {void}
  8. * @private
  9. */
  10. export function updateRemoteParticipants(store: Object) {
  11. const state = store.getState();
  12. const { fakeParticipants, sortedRemoteParticipants, speakersList } = state['features/base/participants'];
  13. const { remoteScreenShares } = state['features/video-layout'];
  14. const screenShares = (remoteScreenShares || []).slice();
  15. let speakers = (speakersList || []).slice();
  16. const remoteParticipants = new Map(sortedRemoteParticipants);
  17. const sharedVideos = fakeParticipants ? Array.from(fakeParticipants.keys()) : [];
  18. for (const screenshare of screenShares) {
  19. remoteParticipants.delete(screenshare);
  20. speakers = speakers.filter(speaker => speaker !== screenshare);
  21. }
  22. for (const sharedVideo of sharedVideos) {
  23. remoteParticipants.delete(sharedVideo);
  24. speakers = speakers.filter(speaker => speaker !== sharedVideo);
  25. }
  26. for (const speaker of speakers) {
  27. remoteParticipants.delete(speaker);
  28. }
  29. const reorderedParticipants
  30. = [ ...screenShares.reverse(), ...sharedVideos, ...speakers, ...Array.from(remoteParticipants.keys()) ];
  31. store.dispatch(setRemoteParticipants(reorderedParticipants));
  32. }
  33. /**
  34. * Private helper to calculate the reordered list of remote participants when a participant leaves.
  35. *
  36. * @param {*} store - The redux store.
  37. * @param {string} participantId - The endpoint id of the participant leaving the call.
  38. * @returns {void}
  39. * @private
  40. */
  41. export function updateRemoteParticipantsOnLeave(store: Object, participantId: ?string = null) {
  42. if (!participantId) {
  43. return;
  44. }
  45. const state = store.getState();
  46. const { remoteParticipants } = state['features/filmstrip'];
  47. const reorderedParticipants = new Set(remoteParticipants);
  48. reorderedParticipants.delete(participantId)
  49. && store.dispatch(setRemoteParticipants(Array.from(reorderedParticipants)));
  50. }