Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

actions.any.js 5.5KB

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