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.js 4.8KB

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