Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
Centralise display name normalisation
Bettenbuk Zoltan79209535eaf5
diff --git a/conference.js b/conference.jsindex 6d6a3b8aa8..475df72b8d 100644--- a/conference.js+++ b/conference.js@@ -76,10 +76,10 @@ import {dominantSpeakerChanged,getAvatarURLByParticipantId,getLocalParticipant,+ getNormalizedDisplayName,getParticipantById,localParticipantConnectionStatusChanged,localParticipantRoleChanged,- MAX_DISPLAY_NAME_LENGTH,participantConnectionStatusChanged,participantPresenceChanged,participantRoleChanged,@@ -1847,7 +1847,7 @@ export default {JitsiConferenceEvents.DISPLAY_NAME_CHANGED,(id, displayName) => {const formattedDisplayName- = displayName.substr(0, MAX_DISPLAY_NAME_LENGTH);+ = getNormalizedDisplayName(displayName);APP.store.dispatch(participantUpdated({conference: room,@@ -2633,8 +2633,7 @@ export default {* @param nickname {string} the new display name*/changeLocalDisplayName(nickname = '') {- const formattedNickname- = nickname.trim().substr(0, MAX_DISPLAY_NAME_LENGTH);+ const formattedNickname = getNormalizedDisplayName(nickname);const { id, name } = getLocalParticipant(APP.store.getState());if (formattedNickname === name) {diff --git a/react/features/base/conference/actions.js b/react/features/base/conference/actions.jsindex ef30ea0042..f9f82a583b 100644--- a/react/features/base/conference/actions.js+++ b/react/features/base/conference/actions.js@@ -10,8 +10,8 @@ import { getName } from '../../app';import { JitsiConferenceEvents } from '../lib-jitsi-meet';import { setAudioMuted, setVideoMuted } from '../media';import {- MAX_DISPLAY_NAME_LENGTH,dominantSpeakerChanged,+ getNormalizedDisplayName,participantConnectionStatusChanged,participantPresenceChanged,participantRoleChanged,@@ -131,7 +131,7 @@ function _addConferenceListeners(conference, dispatch) {(id, displayName) => dispatch(participantUpdated({conference,id,- name: displayName.substr(0, MAX_DISPLAY_NAME_LENGTH)+ name: getNormalizedDisplayName(displayName)})));conference.on(diff --git a/react/features/base/participants/actions.js b/react/features/base/participants/actions.jsindex 9c11310c85..919a158123 100644--- a/react/features/base/participants/actions.js+++ b/react/features/base/participants/actions.js@@ -17,8 +17,7 @@ import {PARTICIPANT_UPDATED,PIN_PARTICIPANT} from './actionTypes';-import { MAX_DISPLAY_NAME_LENGTH } from './constants';-import { getLocalParticipant } from './functions';+import { getLocalParticipant, getNormalizedDisplayName } from './functions';/*** Create an action for when dominant speaker changes.@@ -369,13 +368,17 @@ export function participantRoleChanged(id, role) {* }}*/export function participantUpdated(participant = {}) {+ const participantToUpdate = {+ ...participant+ };+if (participant.name) {- participant.name = participant.name.substr(0, MAX_DISPLAY_NAME_LENGTH);+ participantToUpdate.name = getNormalizedDisplayName(participant.name);}return {type: PARTICIPANT_UPDATED,- participant+ participant: participantToUpdate};}diff --git a/react/features/base/participants/functions.js b/react/features/base/participants/functions.jsindex a02166531d..c1d2c37640 100644--- a/react/features/base/participants/functions.js+++ b/react/features/base/participants/functions.js@@ -6,6 +6,7 @@ import { toState } from '../redux';import {DEFAULT_AVATAR_RELATIVE_PATH,LOCAL_PARTICIPANT_DEFAULT_ID,+ MAX_DISPLAY_NAME_LENGTH,PARTICIPANT_ROLE} from './constants';@@ -94,6 +95,21 @@ export function getLocalParticipant(stateful: Object | Function) {return participants.find(p => p.local);}+/**+ * Normalizes a display name so then no invalid values (padding, length...etc)+ * can be set.+ *+ * @param {string} name - The display name to set.+ * @returns {string}+ */+export function getNormalizedDisplayName(name: string) {+ if (!name || !name.trim()) {+ return undefined;+ }++ return name.trim().substring(0, MAX_DISPLAY_NAME_LENGTH);+}+/*** Returns participant by ID from Redux state.*