Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

actions.any.js 5.4KB

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