選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

actions.any.js 5.6KB

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