[RN] Fix selecting the local participant in the large view

Never show the local participant in the large view unless it's the only
participant.

This fixes 2 issues:

- selecting the local participant when the camera permission wasn't granted
- selecting the other participant when they join a 1-1 call with video muted
This commit is contained in:
Saúl Ibarra Corretgé 2017-10-06 14:43:58 -05:00 committed by Lyubo Marinov
parent 8b0cd310e3
commit bb39ffe562
1 changed files with 20 additions and 20 deletions

View File

@ -2,10 +2,7 @@
import { _handleParticipantError } from '../base/conference'; import { _handleParticipantError } from '../base/conference';
import { MEDIA_TYPE, VIDEO_TYPE } from '../base/media'; import { MEDIA_TYPE, VIDEO_TYPE } from '../base/media';
import { import { getTrackByMediaTypeAndParticipant } from '../base/tracks';
getLocalVideoTrack,
getTrackByMediaTypeAndParticipant
} from '../base/tracks';
import { import {
SELECT_LARGE_VIDEO_PARTICIPANT, SELECT_LARGE_VIDEO_PARTICIPANT,
@ -86,14 +83,13 @@ export function updateKnownLargeVideoResolution(resolution: number) {
} }
/** /**
* Returns the most recent existing video track. It can be local or remote * Returns the most recent existing remote video track.
* video.
* *
* @param {Track[]} tracks - All current tracks. * @param {Track[]} tracks - All current tracks.
* @private * @private
* @returns {(Track|undefined)} * @returns {(Track|undefined)}
*/ */
function _electLastVisibleVideo(tracks) { function _electLastVisibleRemoteVideo(tracks) {
// First we try to get most recent remote video track. // First we try to get most recent remote video track.
for (let i = tracks.length - 1; i >= 0; --i) { for (let i = tracks.length - 1; i >= 0; --i) {
const track = tracks[i]; const track = tracks[i];
@ -102,9 +98,6 @@ function _electLastVisibleVideo(tracks) {
return track; return track;
} }
} }
// And if no remote video tracks are available, we select the local one.
return getLocalVideoTrack(tracks);
} }
/** /**
@ -117,29 +110,36 @@ function _electLastVisibleVideo(tracks) {
* @returns {(string|undefined)} * @returns {(string|undefined)}
*/ */
function _electParticipantInLargeVideo(state) { function _electParticipantInLargeVideo(state) {
// First get the pinned participant. If the local participant is pinned, // First get the pinned participant. If a participant is pinned, they will
// he/she will be shown in LargeVideo. // be shown in the LargeVideo.
const participants = state['features/base/participants']; const participants = state['features/base/participants'];
let participant = participants.find(p => p.pinned); let participant = participants.find(p => p.pinned);
let id = participant ? participant.id : undefined; let id = participant && participant.id;
if (!id) { if (!id) {
// No participant is pinned so get the dominant speaker. But the local // No participant is pinned so get the dominant speaker. But the local
// participant won't be displayed in LargeVideo even if he/she is the // participant won't be displayed in LargeVideo even if he/she is the
// dominant speaker. // dominant speaker.
participant = participants.find(p => p.dominantSpeaker && !p.local); participant = participants.find(p => p.dominantSpeaker && !p.local);
if (participant) { id = participant && participant.id;
id = participant.id;
}
if (!id) { if (!id) {
// There is no dominant speaker so get the participant with the last // There is no dominant speaker so select the participant which last
// visible video track. This may turn out to be the local // had visible video (excluding ourselves).
// participant.
const tracks = state['features/base/tracks']; const tracks = state['features/base/tracks'];
const videoTrack = _electLastVisibleVideo(tracks); const videoTrack = _electLastVisibleRemoteVideo(tracks);
id = videoTrack && videoTrack.participantId; id = videoTrack && videoTrack.participantId;
if (!id) {
// It's possible there is no participant with visible video,
// this can happen for a number or reasons:
// - there is only one participant (the local user)
// - other participants joined with video muted
// As a last resort, pick the last participant.
participant = participants[participants.length - 1];
id = participant && participant.id;
}
} }
} }