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

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