[RN] fix(Avatar): Match the implementation for web
This commit is contained in:
parent
23ddce122b
commit
d74e43ddcc
|
@ -21,9 +21,12 @@ import analytics from './modules/analytics/analytics';
|
||||||
import EventEmitter from "events";
|
import EventEmitter from "events";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
conferenceJoined,
|
AVATAR_ID_COMMAND,
|
||||||
|
AVATAR_URL_COMMAND,
|
||||||
conferenceFailed,
|
conferenceFailed,
|
||||||
conferenceLeft
|
conferenceJoined,
|
||||||
|
conferenceLeft,
|
||||||
|
EMAIL_COMMAND
|
||||||
} from './react/features/base/conference';
|
} from './react/features/base/conference';
|
||||||
import {
|
import {
|
||||||
isFatalJitsiConnectionError
|
isFatalJitsiConnectionError
|
||||||
|
@ -67,12 +70,12 @@ import {VIDEO_CONTAINER_TYPE} from "./modules/UI/videolayout/VideoContainer";
|
||||||
* Known custom conference commands.
|
* Known custom conference commands.
|
||||||
*/
|
*/
|
||||||
const commands = {
|
const commands = {
|
||||||
EMAIL: "email",
|
AVATAR_ID: AVATAR_ID_COMMAND,
|
||||||
AVATAR_URL: "avatar-url",
|
AVATAR_URL: AVATAR_URL_COMMAND,
|
||||||
AVATAR_ID: "avatar-id",
|
CUSTOM_ROLE: "custom-role",
|
||||||
|
EMAIL: EMAIL_COMMAND,
|
||||||
ETHERPAD: "etherpad",
|
ETHERPAD: "etherpad",
|
||||||
SHARED_VIDEO: "shared-video",
|
SHARED_VIDEO: "shared-video"
|
||||||
CUSTOM_ROLE: "custom-role"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,13 +3,7 @@ const logger = require("jitsi-meet-logger").getLogger(__filename);
|
||||||
|
|
||||||
import UIUtil from '../UI/util/UIUtil';
|
import UIUtil from '../UI/util/UIUtil';
|
||||||
import jitsiLocalStorage from '../util/JitsiLocalStorage';
|
import jitsiLocalStorage from '../util/JitsiLocalStorage';
|
||||||
|
import { randomHexString } from '../../react/features/base/util';
|
||||||
function generateUniqueId() {
|
|
||||||
function _p8() {
|
|
||||||
return (Math.random().toString(16) + "000000000").substr(2, 8);
|
|
||||||
}
|
|
||||||
return _p8() + _p8() + _p8() + _p8();
|
|
||||||
}
|
|
||||||
|
|
||||||
let avatarUrl = '';
|
let avatarUrl = '';
|
||||||
|
|
||||||
|
@ -17,7 +11,7 @@ let email = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("email") || '');
|
||||||
let avatarId = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("avatarId") || '');
|
let avatarId = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("avatarId") || '');
|
||||||
if (!avatarId) {
|
if (!avatarId) {
|
||||||
// if there is no avatar id, we generate a unique one and use it forever
|
// if there is no avatar id, we generate a unique one and use it forever
|
||||||
avatarId = generateUniqueId();
|
avatarId = randomHexString(32);
|
||||||
jitsiLocalStorage.setItem("avatarId", avatarId);
|
jitsiLocalStorage.setItem("avatarId", avatarId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import { JitsiConferenceEvents } from '../lib-jitsi-meet';
|
import { JitsiConferenceEvents } from '../lib-jitsi-meet';
|
||||||
import {
|
import {
|
||||||
|
changeParticipantAvatarID,
|
||||||
|
changeParticipantAvatarURL,
|
||||||
changeParticipantEmail,
|
changeParticipantEmail,
|
||||||
dominantSpeakerChanged,
|
dominantSpeakerChanged,
|
||||||
|
getLocalParticipant,
|
||||||
participantJoined,
|
participantJoined,
|
||||||
participantLeft,
|
participantLeft,
|
||||||
participantRoleChanged
|
participantRoleChanged
|
||||||
|
@ -18,7 +21,11 @@ import {
|
||||||
SET_PASSWORD,
|
SET_PASSWORD,
|
||||||
SET_ROOM
|
SET_ROOM
|
||||||
} from './actionTypes';
|
} from './actionTypes';
|
||||||
import { EMAIL_COMMAND } from './constants';
|
import {
|
||||||
|
AVATAR_ID_COMMAND,
|
||||||
|
AVATAR_URL_COMMAND,
|
||||||
|
EMAIL_COMMAND
|
||||||
|
} from './constants';
|
||||||
import { _addLocalTracksToConference } from './functions';
|
import { _addLocalTracksToConference } from './functions';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,11 +76,34 @@ function _addConferenceListeners(conference, dispatch) {
|
||||||
JitsiConferenceEvents.USER_ROLE_CHANGED,
|
JitsiConferenceEvents.USER_ROLE_CHANGED,
|
||||||
(...args) => dispatch(participantRoleChanged(...args)));
|
(...args) => dispatch(participantRoleChanged(...args)));
|
||||||
|
|
||||||
|
conference.addCommandListener(
|
||||||
|
AVATAR_ID_COMMAND,
|
||||||
|
(data, id) => dispatch(changeParticipantAvatarID(id, data.value)));
|
||||||
|
conference.addCommandListener(
|
||||||
|
AVATAR_URL_COMMAND,
|
||||||
|
(data, id) => dispatch(changeParticipantAvatarURL(id, data.value)));
|
||||||
conference.addCommandListener(
|
conference.addCommandListener(
|
||||||
EMAIL_COMMAND,
|
EMAIL_COMMAND,
|
||||||
(data, id) => dispatch(changeParticipantEmail(id, data.value)));
|
(data, id) => dispatch(changeParticipantEmail(id, data.value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the data for the local participant to the conference.
|
||||||
|
*
|
||||||
|
* @param {JitsiConference} conference - The JitsiConference instance.
|
||||||
|
* @param {Object} state - The Redux state.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function _setLocalParticipantData(conference, state) {
|
||||||
|
const localParticipant
|
||||||
|
= getLocalParticipant(state['features/base/participants']);
|
||||||
|
|
||||||
|
conference.removeCommand(AVATAR_ID_COMMAND);
|
||||||
|
conference.sendCommand(AVATAR_ID_COMMAND, {
|
||||||
|
value: localParticipant.avatarID
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signals that a specific conference has failed.
|
* Signals that a specific conference has failed.
|
||||||
*
|
*
|
||||||
|
@ -217,6 +247,8 @@ export function createConference() {
|
||||||
|
|
||||||
_addConferenceListeners(conference, dispatch);
|
_addConferenceListeners(conference, dispatch);
|
||||||
|
|
||||||
|
_setLocalParticipantData(conference, state);
|
||||||
|
|
||||||
conference.join(password);
|
conference.join(password);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,19 @@
|
||||||
/**
|
/**
|
||||||
* The command type for updating a participant's email address.
|
* The command type for updating a participant's avatar ID.
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
export const AVATAR_ID_COMMAND = 'avatar-id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The command type for updating a participant's avatar URL.
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
export const AVATAR_URL_COMMAND = 'avatar-url';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The command type for updating a participant's e-mail address.
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
export * from './actions';
|
export * from './actions';
|
||||||
export * from './actionTypes';
|
export * from './actionTypes';
|
||||||
|
export * from './constants';
|
||||||
export * from './functions';
|
export * from './functions';
|
||||||
|
|
||||||
import './middleware';
|
import './middleware';
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { Container } from '../../react';
|
||||||
import { getTrackByMediaTypeAndParticipant } from '../../tracks';
|
import { getTrackByMediaTypeAndParticipant } from '../../tracks';
|
||||||
|
|
||||||
import Avatar from './Avatar';
|
import Avatar from './Avatar';
|
||||||
import { getParticipantById } from '../functions';
|
import { getAvatarURL, getParticipantById } from '../functions';
|
||||||
import { styles } from './styles';
|
import { styles } from './styles';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -162,14 +162,14 @@ function _toBoolean(value, undefinedValue) {
|
||||||
* }}
|
* }}
|
||||||
*/
|
*/
|
||||||
function _mapStateToProps(state, ownProps) {
|
function _mapStateToProps(state, ownProps) {
|
||||||
const participantId = ownProps.participantId;
|
const { participantId } = ownProps;
|
||||||
const participant
|
|
||||||
= getParticipantById(
|
|
||||||
state['features/base/participants'],
|
|
||||||
participantId);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
_avatar: participant ? participant.avatar : undefined,
|
_avatar:
|
||||||
|
getAvatarURL(
|
||||||
|
getParticipantById(
|
||||||
|
state['features/base/participants'],
|
||||||
|
participantId)),
|
||||||
_videoTrack:
|
_videoTrack:
|
||||||
getTrackByMediaTypeAndParticipant(
|
getTrackByMediaTypeAndParticipant(
|
||||||
state['features/base/tracks'],
|
state['features/base/tracks'],
|
||||||
|
|
|
@ -44,6 +44,9 @@ export function getAvatarURL(participant) {
|
||||||
// from a configured avatar service).
|
// from a configured avatar service).
|
||||||
if (!key) {
|
if (!key) {
|
||||||
key = id;
|
key = id;
|
||||||
|
if (!key) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The deployment is allowed to choose the avatar service which is to
|
// The deployment is allowed to choose the avatar service which is to
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { ReducerRegistry, setStateProperty } from '../redux';
|
import { ReducerRegistry, setStateProperty } from '../redux';
|
||||||
|
import { randomHexString } from '../util';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DOMINANT_SPEAKER_CHANGED,
|
DOMINANT_SPEAKER_CHANGED,
|
||||||
|
@ -12,7 +13,6 @@ import {
|
||||||
LOCAL_PARTICIPANT_DEFAULT_ID,
|
LOCAL_PARTICIPANT_DEFAULT_ID,
|
||||||
PARTICIPANT_ROLE
|
PARTICIPANT_ROLE
|
||||||
} from './constants';
|
} from './constants';
|
||||||
import { getAvatarURL } from './functions';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Participant object.
|
* Participant object.
|
||||||
|
@ -62,25 +62,25 @@ function _participant(state, action) {
|
||||||
|
|
||||||
case PARTICIPANT_ID_CHANGED:
|
case PARTICIPANT_ID_CHANGED:
|
||||||
if (state.id === action.oldValue) {
|
if (state.id === action.oldValue) {
|
||||||
const id = action.newValue;
|
return {
|
||||||
const newState = {
|
|
||||||
...state,
|
...state,
|
||||||
id
|
id: action.newValue
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!newState.avatar) {
|
|
||||||
newState.avatar = getAvatarURL(newState);
|
|
||||||
}
|
|
||||||
|
|
||||||
return newState;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
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 { avatar, dominantSpeaker, email, local, pinned, role }
|
const { avatarURL, dominantSpeaker, email, local, pinned, role }
|
||||||
= participant;
|
= participant;
|
||||||
let { id, name } = participant;
|
let { avatarID, id, name } = participant;
|
||||||
|
|
||||||
|
// avatarID
|
||||||
|
//
|
||||||
|
// TODO Get the avatarID of the local participant from localStorage.
|
||||||
|
if (!avatarID && local) {
|
||||||
|
avatarID = randomHexString(32);
|
||||||
|
}
|
||||||
|
|
||||||
// id
|
// id
|
||||||
//
|
//
|
||||||
|
@ -97,8 +97,9 @@ function _participant(state, action) {
|
||||||
name = local ? 'me' : 'Fellow Jitster';
|
name = local ? 'me' : 'Fellow Jitster';
|
||||||
}
|
}
|
||||||
|
|
||||||
const newState = {
|
return {
|
||||||
avatar,
|
avatarID,
|
||||||
|
avatarURL,
|
||||||
dominantSpeaker: dominantSpeaker || false,
|
dominantSpeaker: dominantSpeaker || false,
|
||||||
email,
|
email,
|
||||||
id,
|
id,
|
||||||
|
@ -107,12 +108,6 @@ function _participant(state, action) {
|
||||||
pinned: pinned || false,
|
pinned: pinned || false,
|
||||||
role: role || PARTICIPANT_ROLE.NONE
|
role: role || PARTICIPANT_ROLE.NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!newState.avatar) {
|
|
||||||
newState.avatar = getAvatarURL(newState);
|
|
||||||
}
|
|
||||||
|
|
||||||
return newState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case PARTICIPANT_UPDATED: {
|
case PARTICIPANT_UPDATED: {
|
||||||
|
@ -130,10 +125,6 @@ function _participant(state, action) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!newState.avatar) {
|
|
||||||
newState.avatar = getAvatarURL(newState);
|
|
||||||
}
|
|
||||||
|
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue