[RN] Show avatar if a participant is not in last N

This commit is contained in:
Saúl Ibarra Corretgé 2017-03-29 11:26:46 +02:00 committed by Lyubo Marinov
parent 7c76f124bf
commit 623b7a8d6f
4 changed files with 81 additions and 8 deletions

View File

@ -1,5 +1,6 @@
import { JitsiConferenceEvents } from '../lib-jitsi-meet'; import { JitsiConferenceEvents } from '../lib-jitsi-meet';
import { import {
changeParticipantLastNStatus,
dominantSpeakerChanged, dominantSpeakerChanged,
getLocalParticipant, getLocalParticipant,
participantJoined, participantJoined,
@ -52,6 +53,10 @@ function _addConferenceListeners(conference, dispatch) {
JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED, JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED,
(...args) => dispatch(dominantSpeakerChanged(...args))); (...args) => dispatch(dominantSpeakerChanged(...args)));
conference.on(
JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
(...args) => _lastNEndpointsChanged(dispatch, ...args));
conference.on( conference.on(
JitsiConferenceEvents.LOCK_STATE_CHANGED, JitsiConferenceEvents.LOCK_STATE_CHANGED,
(...args) => dispatch(_lockStateChanged(conference, ...args))); (...args) => dispatch(_lockStateChanged(conference, ...args)));
@ -263,6 +268,30 @@ export function createConference() {
}; };
} }
/**
* Handles the lastN status changes for participants in the current conference.
* Signals that a participant's lastN status has changed, for each participant
* who entered or left the last N set.
*
* @param {Dispatch} dispatch - Redux dispatch function.
* @param {Array} leavingIds - Ids of participants who are leaving the last N
* set.
* @param {Array} enteringIds - Ids of participants who are entering the last N
* set.
* @returns {void}
*
* @private
*/
function _lastNEndpointsChanged(dispatch, leavingIds = [], enteringIds = []) {
for (const id of leavingIds) {
dispatch(changeParticipantLastNStatus(id, false));
}
for (const id of enteringIds) {
dispatch(changeParticipantLastNStatus(id, true));
}
}
/** /**
* Signals that the lock state of a specific JitsiConference changed. * Signals that the lock state of a specific JitsiConference changed.
* *

View File

@ -8,6 +8,30 @@ import {
} from './actionTypes'; } from './actionTypes';
import { getLocalParticipant } from './functions'; import { getLocalParticipant } from './functions';
/**
* Action to update a participant's lastN status.
*
* @param {string} id - Participant's ID.
* @param {boolean} isInLastN - True if the participant is in the lastN
* endpoints set, false otherwise.
* @returns {{
* type: PARTICIPANT_UPDATED,
* participant: {
* id: string,
* isInLastN: boolean
* }
* }}
*/
export function changeParticipantLastNStatus(id, isInLastN) {
return {
type: PARTICIPANT_UPDATED,
participant: {
id,
isInLastN
}
};
}
/** /**
* Create an action for when dominant speaker changes. * Create an action for when dominant speaker changes.
* *

View File

@ -34,6 +34,13 @@ class ParticipantView extends Component {
*/ */
_avatar: React.PropTypes.string, _avatar: React.PropTypes.string,
/**
* True if the participant is in the last N endpoints set, false if he
* isn't. If undefined, we have no indication, so the same course of
* action as true is taken.
*/
_isInLastN: React.PropTypes.bool,
/** /**
* The video Track of the participant with {@link #participantId}. * The video Track of the participant with {@link #participantId}.
*/ */
@ -85,20 +92,23 @@ class ParticipantView extends Component {
* @returns {ReactElement} * @returns {ReactElement}
*/ */
render() { render() {
// Is the video to be rendered? const {
const videoTrack = this.props._videoTrack; _avatar: avatar,
_isInLastN: isInLastN,
_videoTrack: videoTrack
} = this.props;
// Is the video to be rendered?
// FIXME It's currently impossible to have true as the value of // FIXME It's currently impossible to have true as the value of
// waitForVideoStarted because videoTrack's state videoStarted will be // waitForVideoStarted because videoTrack's state videoStarted will be
// updated only after videoTrack is rendered. // updated only after videoTrack is rendered.
const waitForVideoStarted = false; const waitForVideoStarted = false;
const renderVideo const renderVideo
= shouldRenderVideoTrack(videoTrack, waitForVideoStarted); = shouldRenderVideoTrack(videoTrack, waitForVideoStarted)
&& (typeof isInLastN === 'undefined' || isInLastN);
// Is the avatar to be rendered? // Is the avatar to be rendered?
const avatar = this.props._avatar; const renderAvatar = Boolean(!renderVideo && avatar);
const renderAvatar
= !renderVideo && typeof avatar !== 'undefined' && avatar !== '';
return ( return (
<Container <Container
@ -158,6 +168,7 @@ function _toBoolean(value, undefinedValue) {
* @private * @private
* @returns {{ * @returns {{
* _avatar: string, * _avatar: string,
* _isInLastN: boolean,
* _videoTrack: Track * _videoTrack: Track
* }} * }}
*/ */
@ -170,6 +181,7 @@ function _mapStateToProps(state, ownProps) {
return { return {
_avatar: participant && getAvatarURL(participant), _avatar: participant && getAvatarURL(participant),
_isInLastN: participant && participant.isInLastN,
_videoTrack: _videoTrack:
getTrackByMediaTypeAndParticipant( getTrackByMediaTypeAndParticipant(
state['features/base/tracks'], state['features/base/tracks'],

View File

@ -71,8 +71,15 @@ function _participant(state, action) {
case PARTICIPANT_JOINED: { case PARTICIPANT_JOINED: {
const participant = action.participant; // eslint-disable-line no-shadow const participant = action.participant; // eslint-disable-line no-shadow
const { avatarURL, dominantSpeaker, email, local, pinned, role } const {
= participant; avatarURL,
dominantSpeaker,
email,
isInLastN,
local,
pinned,
role
} = participant;
let { avatarID, id, name } = participant; let { avatarID, id, name } = participant;
// avatarID // avatarID
@ -103,6 +110,7 @@ function _participant(state, action) {
dominantSpeaker: dominantSpeaker || false, dominantSpeaker: dominantSpeaker || false,
email, email,
id, id,
isInLastN,
local: local || false, local: local || false,
name, name,
pinned: pinned || false, pinned: pinned || false,