您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import {
  4. createSelectParticipantFailedEvent,
  5. sendAnalytics
  6. } from '../analytics';
  7. import { _handleParticipantError } from '../base/conference';
  8. import { MEDIA_TYPE } from '../base/media';
  9. import { getParticipants } from '../base/participants';
  10. import { reportError } from '../base/util';
  11. import { shouldDisplayTileView } from '../video-layout';
  12. import {
  13. SELECT_LARGE_VIDEO_PARTICIPANT,
  14. UPDATE_KNOWN_LARGE_VIDEO_RESOLUTION
  15. } from './actionTypes';
  16. declare var APP: Object;
  17. /**
  18. * Signals conference to select a participant.
  19. *
  20. * @returns {Function}
  21. */
  22. export function selectParticipant() {
  23. return (dispatch: Dispatch<any>, getState: Function) => {
  24. const state = getState();
  25. const { conference } = state['features/base/conference'];
  26. if (conference) {
  27. const ids = shouldDisplayTileView(state)
  28. ? getParticipants(state).map(participant => participant.id)
  29. : [ state['features/large-video'].participantId ];
  30. try {
  31. conference.selectParticipants(ids);
  32. } catch (err) {
  33. _handleParticipantError(err);
  34. sendAnalytics(createSelectParticipantFailedEvent(err));
  35. reportError(
  36. err, `Failed to select participants ${ids.toString()}`);
  37. }
  38. }
  39. };
  40. }
  41. /**
  42. * Action to select the participant to be displayed in LargeVideo based on the
  43. * participant id provided. If a partcipant id is not provided, the LargeVideo
  44. * participant will be selected based on a variety of factors: If there is a
  45. * dominant or pinned speaker, or if there are remote tracks, etc.
  46. *
  47. * @param {string} participant - The participant id of the user that needs to be
  48. * displayed on the large video.
  49. * @returns {Function}
  50. */
  51. export function selectParticipantInLargeVideo(participant: ?string) {
  52. return (dispatch: Dispatch<any>, getState: Function) => {
  53. const state = getState();
  54. const participantId = participant ?? _electParticipantInLargeVideo(state);
  55. const largeVideo = state['features/large-video'];
  56. if (participantId !== largeVideo.participantId) {
  57. dispatch({
  58. type: SELECT_LARGE_VIDEO_PARTICIPANT,
  59. participantId
  60. });
  61. dispatch(selectParticipant());
  62. }
  63. };
  64. }
  65. /**
  66. * Updates the currently seen resolution of the video displayed on large video.
  67. *
  68. * @param {number} resolution - The current resolution (height) of the video.
  69. * @returns {{
  70. * type: UPDATE_KNOWN_LARGE_VIDEO_RESOLUTION,
  71. * resolution: number
  72. * }}
  73. */
  74. export function updateKnownLargeVideoResolution(resolution: number) {
  75. return {
  76. type: UPDATE_KNOWN_LARGE_VIDEO_RESOLUTION,
  77. resolution
  78. };
  79. }
  80. /**
  81. * Returns the most recent existing remote video track.
  82. *
  83. * @param {Track[]} tracks - All current tracks.
  84. * @private
  85. * @returns {(Track|undefined)}
  86. */
  87. function _electLastVisibleRemoteVideo(tracks) {
  88. // First we try to get most recent remote video track.
  89. for (let i = tracks.length - 1; i >= 0; --i) {
  90. const track = tracks[i];
  91. if (!track.local && track.mediaType === MEDIA_TYPE.VIDEO) {
  92. return track;
  93. }
  94. }
  95. }
  96. /**
  97. * Returns the identifier of the participant who is to be on the stage and
  98. * should be displayed in {@code LargeVideo}.
  99. *
  100. * @param {Object} state - The Redux state from which the participant to be
  101. * displayed in {@code LargeVideo} is to be elected.
  102. * @private
  103. * @returns {(string|undefined)}
  104. */
  105. function _electParticipantInLargeVideo(state) {
  106. // 1. If a participant is pinned, they will be shown in the LargeVideo (
  107. // regardless of whether they are local or remote).
  108. const participants = state['features/base/participants'];
  109. let participant = participants.find(p => p.pinned);
  110. let id = participant && participant.id;
  111. if (!id) {
  112. // 2. No participant is pinned so get the dominant speaker. But the
  113. // local participant won't be displayed in LargeVideo even if she is
  114. // the dominant speaker.
  115. participant = participants.find(p => p.dominantSpeaker && !p.local);
  116. id = participant && participant.id;
  117. if (!id) {
  118. // 3. There is no dominant speaker so select the remote participant
  119. // who last had visible video.
  120. const tracks = state['features/base/tracks'];
  121. const videoTrack = _electLastVisibleRemoteVideo(tracks);
  122. id = videoTrack && videoTrack.participantId;
  123. if (!id) {
  124. // 4. It's possible there is no participant with visible video.
  125. // This can happen for a number of reasons:
  126. // - there is only one participant (i.e. the local user),
  127. // - other participants joined with video muted.
  128. // As a last resort, pick the last participant who joined the
  129. // conference (regardless of whether they are local or
  130. // remote).
  131. //
  132. // HOWEVER: We don't want to show poltergeist or other bot type participants on stage
  133. // automatically, because it's misleading (users may think they are already
  134. // joined and maybe speaking).
  135. for (let i = participants.length; i > 0 && !participant; i--) {
  136. const p = participants[i - 1];
  137. !p.botType && (participant = p);
  138. }
  139. id = participant && participant.id;
  140. }
  141. }
  142. }
  143. return id;
  144. }