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.

actions.any.js 5.0KB

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