Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

actions.any.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { MEDIA_TYPE } from '../base/media';
  4. import {
  5. getDominantSpeakerParticipant,
  6. getLocalParticipant,
  7. getPinnedParticipant,
  8. getRemoteParticipants
  9. } from '../base/participants';
  10. import {
  11. SELECT_LARGE_VIDEO_PARTICIPANT,
  12. UPDATE_KNOWN_LARGE_VIDEO_RESOLUTION
  13. } from './actionTypes';
  14. /**
  15. * Action to select the participant to be displayed in LargeVideo based on the
  16. * participant id provided. If a participant id is not provided, the LargeVideo
  17. * participant will be selected based on a variety of factors: If there is a
  18. * dominant or pinned speaker, or if there are remote tracks, etc.
  19. *
  20. * @param {string} participant - The participant id of the user that needs to be
  21. * displayed on the large video.
  22. * @returns {Function}
  23. */
  24. export function selectParticipantInLargeVideo(participant: ?string) {
  25. return (dispatch: Dispatch<any>, getState: Function) => {
  26. const state = getState();
  27. const participantId = participant ?? _electParticipantInLargeVideo(state);
  28. const largeVideo = state['features/large-video'];
  29. const remoteScreenShares = state['features/video-layout'].remoteScreenShares;
  30. let latestScreenshareParticipantId;
  31. if (remoteScreenShares && remoteScreenShares.length) {
  32. latestScreenshareParticipantId = remoteScreenShares[remoteScreenShares.length - 1];
  33. }
  34. // When trying to auto pin screenshare, always select the endpoint even though it happens to be
  35. // the large video participant in redux (for the reasons listed above in the large video selection
  36. // logic above). The auto pin screenshare logic kicks in after the track is added
  37. // (which updates the large video participant and selects all endpoints because of the auto tile
  38. // view mode). If the screenshare endpoint is not among the forwarded endpoints from the bridge,
  39. // it needs to be selected again at this point.
  40. if (participantId !== largeVideo.participantId || participantId === latestScreenshareParticipantId) {
  41. dispatch({
  42. type: SELECT_LARGE_VIDEO_PARTICIPANT,
  43. participantId
  44. });
  45. }
  46. };
  47. }
  48. /**
  49. * Updates the currently seen resolution of the video displayed on large video.
  50. *
  51. * @param {number} resolution - The current resolution (height) of the video.
  52. * @returns {{
  53. * type: UPDATE_KNOWN_LARGE_VIDEO_RESOLUTION,
  54. * resolution: number
  55. * }}
  56. */
  57. export function updateKnownLargeVideoResolution(resolution: number) {
  58. return {
  59. type: UPDATE_KNOWN_LARGE_VIDEO_RESOLUTION,
  60. resolution
  61. };
  62. }
  63. /**
  64. * Returns the most recent existing remote video track.
  65. *
  66. * @param {Track[]} tracks - All current tracks.
  67. * @private
  68. * @returns {(Track|undefined)}
  69. */
  70. function _electLastVisibleRemoteVideo(tracks) {
  71. // First we try to get most recent remote video track.
  72. for (let i = tracks.length - 1; i >= 0; --i) {
  73. const track = tracks[i];
  74. if (!track.local && track.mediaType === MEDIA_TYPE.VIDEO) {
  75. return track;
  76. }
  77. }
  78. }
  79. /**
  80. * Returns the identifier of the participant who is to be on the stage and
  81. * should be displayed in {@code LargeVideo}.
  82. *
  83. * @param {Object} state - The Redux state from which the participant to be
  84. * displayed in {@code LargeVideo} is to be elected.
  85. * @private
  86. * @returns {(string|undefined)}
  87. */
  88. function _electParticipantInLargeVideo(state) {
  89. // 1. If a participant is pinned, they will be shown in the LargeVideo
  90. // (regardless of whether they are local or remote).
  91. let participant = getPinnedParticipant(state);
  92. if (participant) {
  93. return participant.id;
  94. }
  95. // 2. Next, pick the most recent remote screenshare that was added to the conference.
  96. const remoteScreenShares = state['features/video-layout'].remoteScreenShares;
  97. if (remoteScreenShares?.length) {
  98. return remoteScreenShares[remoteScreenShares.length - 1];
  99. }
  100. // 3. Next, pick the dominant speaker (other than self).
  101. participant = getDominantSpeakerParticipant(state);
  102. if (participant && !participant.local) {
  103. return participant.id;
  104. }
  105. // In case this is the local participant.
  106. participant = undefined;
  107. // 4. Next, pick the most recent participant with video.
  108. const tracks = state['features/base/tracks'];
  109. const videoTrack = _electLastVisibleRemoteVideo(tracks);
  110. if (videoTrack) {
  111. return videoTrack.participantId;
  112. }
  113. // 5. As a last resort, select the participant that joined last (other than poltergist or other bot type
  114. // participants).
  115. const participants = [ ...getRemoteParticipants(state).values() ];
  116. for (let i = participants.length; i > 0 && !participant; i--) {
  117. const p = participants[i - 1];
  118. !p.botType && (participant = p);
  119. }
  120. if (participant) {
  121. return participant.id;
  122. }
  123. return getLocalParticipant(state)?.id;
  124. }