Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(participants): store user context data for external API events and functions

Mihaela Dumitru2eb07cb79fb5
diff --git a/react/features/base/conference/functions.ts b/react/features/base/conference/functions.ts
index fef9fe745f..ac4760b737 100644
--- a/react/features/base/conference/functions.ts
+++ b/react/features/base/conference/functions.ts
@@ -93,10 +93,17 @@ export function commonUserJoinedHandling(
if (!user.isHidden()) {
const isReplacing = user?.isReplacing();
const isPromoted = conference?.getMetadataHandler().getMetadata()?.visitors?.promoted?.[id];
+ const userIdentity = user.getIdentity()?.user;
+
+ // Map identity from JWT context to userContext for external API
+ const userContext = userIdentity ? {
+ id: userIdentity.id,
+ name: userIdentity.name
+ } : undefined;
// the identity and avatar come from jwt and never change in the presence
dispatch(participantJoined({
- avatarURL: user.getIdentity()?.user?.avatar,
+ avatarURL: userIdentity?.avatar,
botType: user.getBotType(),
conference,
id,
@@ -105,7 +112,8 @@ export function commonUserJoinedHandling(
role: user.getRole(),
isPromoted,
isReplacing,
- sources: user.getSources()
+ sources: user.getSources(),
+ userContext
}));
}
}
diff --git a/react/features/base/participants/middleware.ts b/react/features/base/participants/middleware.ts
index ab66928a99..697bc74bad 100644
--- a/react/features/base/participants/middleware.ts
+++ b/react/features/base/participants/middleware.ts
@@ -606,13 +606,21 @@ function _e2eeUpdated({ getState, dispatch }: IStore, conference: IJitsiConferen
function _localParticipantJoined({ getState, dispatch }: IStore, next: Function, action: AnyAction) {
const result = next(action);
- const settings = getState()['features/base/settings'];
+ const state = getState();
+ const settings = state['features/base/settings'];
+ const jwtUser = state['features/base/jwt']?.user;
+
+ const userContext = jwtUser ? {
+ id: jwtUser.id,
+ name: jwtUser.name
+ } : undefined;
dispatch(localParticipantJoined({
avatarURL: settings.avatarURL,
email: settings.email,
name: settings.displayName,
- id: ''
+ id: '',
+ userContext
}));
return result;
diff --git a/react/features/base/participants/reducer.ts b/react/features/base/participants/reducer.ts
index 3b14ad03bc..f4c89f2f9b 100644
--- a/react/features/base/participants/reducer.ts
+++ b/react/features/base/participants/reducer.ts
@@ -627,7 +627,8 @@ function _participantJoined({ participant }: { participant: IParticipant; }) {
pinned,
presence,
role,
- sources
+ sources,
+ userContext
} = participant;
let { conference, id } = participant;
@@ -659,7 +660,8 @@ function _participantJoined({ participant }: { participant: IParticipant; }) {
pinned: pinned || false,
presence,
role: role || PARTICIPANT_ROLE.NONE,
- sources
+ sources,
+ userContext
};
}
diff --git a/react/features/base/participants/types.ts b/react/features/base/participants/types.ts
index 04a0b8d3c2..4f7ad48862 100644
--- a/react/features/base/participants/types.ts
+++ b/react/features/base/participants/types.ts
@@ -41,6 +41,12 @@ export interface IParticipant {
role?: string;
sources?: Map<string, Map<string, ISourceInfo>>;
supportsRemoteControl?: boolean;
+ userContext?: IUserContext;
+}
+
+export interface IUserContext {
+ id?: string;
+ name?: string;
}
export interface ILocalParticipant extends IParticipant {
diff --git a/react/features/breakout-rooms/functions.ts b/react/features/breakout-rooms/functions.ts
index 23429fe6ec..5fc2abedc1 100644
--- a/react/features/breakout-rooms/functions.ts
+++ b/react/features/breakout-rooms/functions.ts
@@ -44,6 +44,16 @@ export const getMainRoom = (stateful: IStateful) => {
* @returns {IRoomsInfo} The rooms info.
*/
export const getRoomsInfo = (stateful: IStateful) => {
+ const state = toState(stateful);
+ const localParticipant = getLocalParticipant(stateful);
+ const jwtUser = state['features/base/jwt']?.user;
+ const localUserContext = jwtUser ? {
+ id: jwtUser.id,
+ name: jwtUser.name
+ } : {
+ id: localParticipant?.jwtId,
+ name: localParticipant?.name
+ };
const breakoutRooms = getBreakoutRooms(stateful);
const conference = getCurrentConference(stateful);
@@ -57,7 +67,6 @@ export const getRoomsInfo = (stateful: IStateful) => {
const conferenceParticipants = conference?.getParticipants()
.filter((participant: IJitsiParticipant) => !participant.isHidden());
- const localParticipant = getLocalParticipant(stateful);
let localParticipantInfo;
if (localParticipant) {
@@ -65,7 +74,8 @@ export const getRoomsInfo = (stateful: IStateful) => {
role: localParticipant.role,
displayName: localParticipant.name,
avatarUrl: localParticipant.loadableAvatarUrl,
- id: localParticipant.id
+ id: localParticipant.id,
+ userContext: localUserContext
};
}
@@ -86,7 +96,8 @@ export const getRoomsInfo = (stateful: IStateful) => {
role: participantItem.getRole(),
displayName: participantItem.getDisplayName(),
avatarUrl: storeParticipant?.loadableAvatarUrl,
- id: participantItem.getId()
+ id: participantItem.getId(),
+ userContext: storeParticipant?.userContext
} as IRoomInfoParticipant;
}) ]
: [ localParticipantInfo ]
@@ -110,13 +121,18 @@ export const getRoomsInfo = (stateful: IStateful) => {
const storeParticipant = getParticipantById(stateful,
ids.length > 1 ? ids[1] : participantItem.jid);
+ // Check if this is the local participant
+ const isLocal = storeParticipant?.id === localParticipant?.id;
+ const userContext = isLocal ? localUserContext : (storeParticipant?.userContext || participantItem.userContext);
+
return {
jid: participantItem?.jid,
role: participantItem?.role,
displayName: participantItem?.displayName,
avatarUrl: storeParticipant?.loadableAvatarUrl,
id: storeParticipant ? storeParticipant.id
- : participantLongId
+ : participantLongId,
+ userContext
} as IRoomInfoParticipant;
}) : []
} as IRoomInfo;
diff --git a/react/features/breakout-rooms/middleware.ts b/react/features/breakout-rooms/middleware.ts
index 2e27666a82..b4d5827a04 100644
--- a/react/features/breakout-rooms/middleware.ts
+++ b/react/features/breakout-rooms/middleware.ts
@@ -44,19 +44,59 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
switch (type) {
case UPDATE_BREAKOUT_ROOMS: {
- // edit name if it was overwritten
+ // Enrich participants with userContext from Redux store
if (!action.updatedNames) {
- const { overwrittenNameList } = getState()['features/base/participants'];
+ const state = getState();
+ const { overwrittenNameList, local: localParticipant } = state['features/base/participants'];
+ const jwtUser = state['features/base/jwt']?.user;
+ const localUserContext = jwtUser ? {
+ id: jwtUser.id,
+ name: jwtUser.name
+ } : {
+ id: localParticipant?.jwtId,
+ name: localParticipant?.name
+ };
+
+ // Get existing userContext cache
+ const existingCache = state['features/breakout-rooms'].userContextCache || {};
+ const newCache = { ...existingCache };
+
+ const newRooms: IRooms = {};
+
+ Object.entries(action.rooms as IRooms).forEach(([ key, r ]) => {
+ let participants = r?.participants || {};
+
+ // Add userContext to each participant
+ const enhancedParticipants: typeof participants = {};
+
+ for (const [ participantJid, participantData ] of Object.entries(participants)) {
+ const ids = participantJid.split('/');
+ const participantId = ids.length > 1 ? ids[1] : participantData.jid;
+ const storeParticipant = getParticipantById(state, participantId);
+ const isLocal = storeParticipant?.id === localParticipant?.id;
+
+ // Try to get userContext from: local, store, cache, or incoming data
+ const userContext = isLocal
+ ? localUserContext
+ : (storeParticipant?.userContext || newCache[participantId] || participantData.userContext);
+
+ // Update cache if we have userContext
+ if (userContext && participantId) {
+ newCache[participantId] = userContext;
+ }
- if (Object.keys(overwrittenNameList).length > 0) {
- const newRooms: IRooms = {};
+ enhancedParticipants[participantJid] = {
+ ...participantData,
+ userContext
+ };
+ }
- Object.entries(action.rooms as IRooms).forEach(([ key, r ]) => {
- let participants = r?.participants || {};
- let jid;
+ participants = enhancedParticipants;
+ // Apply overwritten display names
+ if (Object.keys(overwrittenNameList).length > 0) {
for (const id of Object.keys(overwrittenNameList)) {
- jid = Object.keys(participants).find(p => p.slice(p.indexOf('/') + 1) === id);
+ const jid = Object.keys(participants).find(p => p.slice(p.indexOf('/') + 1) === id);
if (jid) {
participants = {
@@ -68,15 +108,16 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
};
}
}
+ }
- newRooms[key] = {
- ...r,
- participants
- };
- });
+ newRooms[key] = {
+ ...r,
+ participants
+ };
+ });
- action.rooms = newRooms;
- }
+ action.rooms = newRooms;
+ action.userContextCache = newCache;
}
// edit the chat history to match names for participants in breakout rooms
diff --git a/react/features/breakout-rooms/reducer.ts b/react/features/breakout-rooms/reducer.ts
index 5412c28b79..964064b6ac 100644
--- a/react/features/breakout-rooms/reducer.ts
+++ b/react/features/breakout-rooms/reducer.ts
@@ -10,12 +10,19 @@ import { IRooms } from './types';
const DEFAULT_STATE = {
rooms: {},
- roomCounter: 0
+ roomCounter: 0,
+ userContextCache: {}
};
export interface IBreakoutRoomsState {
roomCounter: number;
rooms: IRooms;
+ userContextCache: {
+ [participantId: string]: {
+ id?: string;
+ name?: string;
+ };
+ };
}
/**
@@ -29,12 +36,13 @@ ReducerRegistry.register<IBreakoutRoomsState>(FEATURE_KEY, (state = DEFAULT_STAT
roomCounter: action.roomCounter
};
case UPDATE_BREAKOUT_ROOMS: {
- const { roomCounter, rooms } = action;
+ const { roomCounter, rooms, userContextCache } = action;
return {
...state,
roomCounter,
- rooms
+ rooms,
+ userContextCache: userContextCache || state.userContextCache
};
}
case _RESET_BREAKOUT_ROOMS: {
diff --git a/react/features/breakout-rooms/types.ts b/react/features/breakout-rooms/types.ts
index bb4a47f6e4..b7fde49ac8 100644
--- a/react/features/breakout-rooms/types.ts
+++ b/react/features/breakout-rooms/types.ts
@@ -8,6 +8,10 @@ export interface IRoom {
displayName: string;
jid: string;
role: string;
+ userContext?: {
+ id?: string;
+ name?: string;
+ };
};
};
}
@@ -33,4 +37,8 @@ export interface IRoomInfoParticipant {
id: string;
jid: string;
role: string;
+ userContext?: {
+ id?: string;
+ name?: string;
+ };
}
diff --git a/react/features/external-api/middleware.ts b/react/features/external-api/middleware.ts
index 039509f963..2db11beda5 100644
--- a/react/features/external-api/middleware.ts
+++ b/react/features/external-api/middleware.ts
@@ -212,7 +212,7 @@ MiddlewareRegistry.register(store => next => action => {
const state = store.getState();
const { defaultRemoteDisplayName } = state['features/base/config'];
const { participant } = action;
- const { fakeParticipant, id, local, name } = participant;
+ const { fakeParticipant, id, local, name, userContext } = participant;
// The version of external api outside of middleware did not emit
// the local participant being created.
@@ -225,7 +225,8 @@ MiddlewareRegistry.register(store => next => action => {
APP.API.notifyUserJoined(id, {
displayName: name,
formattedDisplayName: appendSuffix(
- name || defaultRemoteDisplayName)
+ name || defaultRemoteDisplayName),
+ userContext
});
}