Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

functions.any.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. * @param {string} participantId - The endpoint id of the participant that joined the call.
  8. * @returns {void}
  9. * @private
  10. */
  11. export function updateRemoteParticipants(store: Object, participantId: ?number) {
  12. const state = store.getState();
  13. const { enableThumbnailReordering = true } = state['features/base/config'];
  14. let reorderedParticipants = [];
  15. if (!enableThumbnailReordering) {
  16. if (participantId) {
  17. const { remoteParticipants } = state['features/filmstrip'];
  18. reorderedParticipants = [ ...remoteParticipants, participantId ];
  19. store.dispatch(setRemoteParticipants(reorderedParticipants));
  20. }
  21. return;
  22. }
  23. const {
  24. fakeParticipants,
  25. sortedRemoteParticipants,
  26. sortedRemoteScreenshares,
  27. speakersList
  28. } = state['features/base/participants'];
  29. const remoteParticipants = new Map(sortedRemoteParticipants);
  30. const screenShares = new Map(sortedRemoteScreenshares);
  31. const sharedVideos = fakeParticipants ? Array.from(fakeParticipants.keys()) : [];
  32. const speakers = new Map(speakersList);
  33. for (const screenshare of screenShares.keys()) {
  34. remoteParticipants.delete(screenshare);
  35. speakers.delete(screenshare);
  36. }
  37. for (const sharedVideo of sharedVideos) {
  38. remoteParticipants.delete(sharedVideo);
  39. speakers.delete(sharedVideo);
  40. }
  41. for (const speaker of speakers.keys()) {
  42. remoteParticipants.delete(speaker);
  43. }
  44. // Always update the order of the thumnails.
  45. reorderedParticipants = [
  46. ...Array.from(screenShares.keys()),
  47. ...sharedVideos,
  48. ...Array.from(speakers.keys()),
  49. ...Array.from(remoteParticipants.keys())
  50. ];
  51. store.dispatch(setRemoteParticipants(reorderedParticipants));
  52. }
  53. /**
  54. * Private helper to calculate the reordered list of remote participants when a participant leaves.
  55. *
  56. * @param {*} store - The redux store.
  57. * @param {string} participantId - The endpoint id of the participant leaving the call.
  58. * @returns {void}
  59. * @private
  60. */
  61. export function updateRemoteParticipantsOnLeave(store: Object, participantId: ?string = null) {
  62. if (!participantId) {
  63. return;
  64. }
  65. const state = store.getState();
  66. const { remoteParticipants } = state['features/filmstrip'];
  67. const reorderedParticipants = new Set(remoteParticipants);
  68. reorderedParticipants.delete(participantId)
  69. && store.dispatch(setRemoteParticipants(Array.from(reorderedParticipants)));
  70. }