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 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // @flow
  2. import { getSourceNameSignalingFeatureFlag } from '../base/config';
  3. import { getFakeScreenShareParticipantOwnerId } from '../base/participants';
  4. import { setRemoteParticipants } from './actions';
  5. import { isReorderingEnabled } from './functions';
  6. /**
  7. * Computes the reorderd list of the remote participants.
  8. *
  9. * @param {*} store - The redux store.
  10. * @param {string} participantId - The endpoint id of the participant that joined the call.
  11. * @returns {void}
  12. * @private
  13. */
  14. export function updateRemoteParticipants(store: Object, participantId: ?number) {
  15. const state = store.getState();
  16. let reorderedParticipants = [];
  17. const { sortedRemoteFakeScreenShareParticipants } = state['features/base/participants'];
  18. if (!isReorderingEnabled(state) && !sortedRemoteFakeScreenShareParticipants.size) {
  19. if (participantId) {
  20. const { remoteParticipants } = state['features/filmstrip'];
  21. reorderedParticipants = [ ...remoteParticipants, participantId ];
  22. store.dispatch(setRemoteParticipants(reorderedParticipants));
  23. }
  24. return;
  25. }
  26. const {
  27. fakeParticipants,
  28. sortedRemoteParticipants,
  29. sortedRemoteScreenshares,
  30. speakersList
  31. } = state['features/base/participants'];
  32. const remoteParticipants = new Map(sortedRemoteParticipants);
  33. const screenShares = new Map(sortedRemoteScreenshares);
  34. const screenShareParticipants = sortedRemoteFakeScreenShareParticipants
  35. ? [ ...sortedRemoteFakeScreenShareParticipants.keys() ] : [];
  36. const sharedVideos = fakeParticipants ? Array.from(fakeParticipants.keys()) : [];
  37. const speakers = new Map(speakersList);
  38. if (getSourceNameSignalingFeatureFlag(state)) {
  39. for (const screenshare of screenShareParticipants) {
  40. const ownerId = getFakeScreenShareParticipantOwnerId(screenshare);
  41. remoteParticipants.delete(ownerId);
  42. remoteParticipants.delete(screenshare);
  43. speakers.delete(ownerId);
  44. speakers.delete(screenshare);
  45. }
  46. } else {
  47. for (const screenshare of screenShares.keys()) {
  48. remoteParticipants.delete(screenshare);
  49. speakers.delete(screenshare);
  50. }
  51. }
  52. for (const sharedVideo of sharedVideos) {
  53. remoteParticipants.delete(sharedVideo);
  54. speakers.delete(sharedVideo);
  55. }
  56. for (const speaker of speakers.keys()) {
  57. remoteParticipants.delete(speaker);
  58. }
  59. if (getSourceNameSignalingFeatureFlag(state)) {
  60. // Always update the order of the thumnails.
  61. const participantsWithScreenShare = screenShareParticipants.reduce((acc, screenshare) => {
  62. const ownerId = getFakeScreenShareParticipantOwnerId(screenshare);
  63. acc.push(ownerId);
  64. acc.push(screenshare);
  65. return acc;
  66. }, []);
  67. reorderedParticipants = [
  68. ...participantsWithScreenShare,
  69. ...sharedVideos,
  70. ...Array.from(speakers.keys()),
  71. ...Array.from(remoteParticipants.keys())
  72. ];
  73. } else {
  74. // Always update the order of the thumnails.
  75. reorderedParticipants = [
  76. ...Array.from(screenShares.keys()),
  77. ...sharedVideos,
  78. ...Array.from(speakers.keys()),
  79. ...Array.from(remoteParticipants.keys())
  80. ];
  81. }
  82. store.dispatch(setRemoteParticipants(reorderedParticipants));
  83. }
  84. /**
  85. * Private helper to calculate the reordered list of remote participants when a participant leaves.
  86. *
  87. * @param {*} store - The redux store.
  88. * @param {string} participantId - The endpoint id of the participant leaving the call.
  89. * @returns {void}
  90. * @private
  91. */
  92. export function updateRemoteParticipantsOnLeave(store: Object, participantId: ?string = null) {
  93. if (!participantId) {
  94. return;
  95. }
  96. const state = store.getState();
  97. const { remoteParticipants } = state['features/filmstrip'];
  98. const reorderedParticipants = new Set(remoteParticipants);
  99. reorderedParticipants.delete(participantId)
  100. && store.dispatch(setRemoteParticipants(Array.from(reorderedParticipants)));
  101. }