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
feat(jwt): Delay loading of avatar. (#16111)
Дамян Минков94813163e857
diff --git a/react/features/base/jwt/actionTypes.ts b/react/features/base/jwt/actionTypes.tsindex d7d4f7b8e7..9b7ca272a6 100644--- a/react/features/base/jwt/actionTypes.ts+++ b/react/features/base/jwt/actionTypes.ts@@ -1,3 +1,13 @@+/**+ * The type of redux action which set an avatar URL for delayed loading.+ *+ * {+ * type: SET_DELAYED_LOAD_OF_AVATAR_URL+ * avatarUrl: string+ * }+ */+export const SET_DELAYED_LOAD_OF_AVATAR_URL = 'SET_DELAYED_LOAD_OF_AVATAR_URL';+/*** The type of redux action which stores a specific JSON Web Token (JWT) into* the redux store.@@ -8,3 +18,13 @@* }*/export const SET_JWT = 'SET_JWT';++/**+ * The type of redux action which sets a known avatar URL.+ *+ * {+ * type: SET_KNOWN_AVATAR_URL,+ * avatarUrl: string+ * }+ */+export const SET_KNOWN_AVATAR_URL = 'SET_KNOWN_AVATAR_URL';diff --git a/react/features/base/jwt/actions.ts b/react/features/base/jwt/actions.tsindex 39d7557be7..b38875baf9 100644--- a/react/features/base/jwt/actions.ts+++ b/react/features/base/jwt/actions.ts@@ -1,11 +1,27 @@-import { SET_JWT } from './actionTypes';+import { SET_DELAYED_LOAD_OF_AVATAR_URL, SET_JWT, SET_KNOWN_AVATAR_URL } from './actionTypes';++/**+ * Sets an avatar URL for delayed loading.+ *+ * @param {string} avatarUrl - The avatar URL to set for delayed loading.+ * @returns {{+ * type: SET_DELAYED_LOAD_OF_AVATAR_URL,+ * avatarUrl: string+ * }}+ */+export function setDelayedLoadOfAvatarUrl(avatarUrl?: string) {+ return {+ type: SET_DELAYED_LOAD_OF_AVATAR_URL,+ avatarUrl+ };+}/*** Stores a specific JSON Web Token (JWT) into the redux store.** @param {string} [jwt] - The JSON Web Token (JWT) to store.* @returns {{- * type: SET_TOKEN_DATA,+ * type: SET_JWT,* jwt: (string|undefined)* }}*/@@ -15,3 +31,19 @@ export function setJWT(jwt?: string) {jwt};}++/**+ * Sets a known avatar URL.+ *+ * @param {string} avatarUrl - The avatar URL to set as known.+ * @returns {{+ * type: SET_KNOWN_AVATAR_URL,+ * avatarUrl: string+ * }}+ */+export function setKnownAvatarUrl(avatarUrl: string) {+ return {+ type: SET_KNOWN_AVATAR_URL,+ avatarUrl+ };+}diff --git a/react/features/base/jwt/middleware.ts b/react/features/base/jwt/middleware.tsindex 4bad35069c..b5938dc736 100644--- a/react/features/base/jwt/middleware.ts+++ b/react/features/base/jwt/middleware.ts@@ -5,7 +5,7 @@ import { AnyAction } from 'redux';import { IStore } from '../../app/types';import { isVpaasMeeting } from '../../jaas/functions';import { SET_CONFIG } from '../config/actionTypes';-import { SET_LOCATION_URL } from '../connection/actionTypes';+import { CONNECTION_ESTABLISHED, SET_LOCATION_URL } from '../connection/actionTypes';import { participantUpdated } from '../participants/actions';import { getLocalParticipant } from '../participants/functions';import { IParticipant } from '../participants/types';@@ -13,9 +13,23 @@ import MiddlewareRegistry from '../redux/MiddlewareRegistry';import { parseURIString } from '../util/uri';import { SET_JWT } from './actionTypes';-import { setJWT } from './actions';+import { setDelayedLoadOfAvatarUrl, setJWT, setKnownAvatarUrl } from './actions';import { parseJWTFromURLParams } from './functions';import logger from './logger';+import StateListenerRegistry from '../redux/StateListenerRegistry';+import { getCurrentConference } from '../conference/functions';++/**+ * Set up a state change listener to perform maintenance tasks when the conference+ * is left or failed, e.g. Clear any delayed load avatar url.+ */+StateListenerRegistry.register(+ state => getCurrentConference(state),+ (conference, { dispatch }, previousConference): void => {+ if (conference !== previousConference) {+ dispatch(setDelayedLoadOfAvatarUrl());+ }+ });/*** Middleware to parse token data upon setting a new room URL.@@ -31,7 +45,18 @@ MiddlewareRegistry.register(store => next => action => {// XXX The JSON Web Token (JWT) is not the only piece of state that we// have decided to store in the feature jwtreturn _setConfigOrLocationURL(store, next, action);-+ case CONNECTION_ESTABLISHED: {+ const state = store.getState();+ const delayedLoadOfAvatarUrl = state['features/base/jwt'].delayedLoadOfAvatarUrl;++ if (delayedLoadOfAvatarUrl) {+ _overwriteLocalParticipant(store, {+ avatarURL: delayedLoadOfAvatarUrl+ });+ store.dispatch(setDelayedLoadOfAvatarUrl());+ store.dispatch(setKnownAvatarUrl(delayedLoadOfAvatarUrl));+ }+ }case SET_JWT:return _setJWT(store, next, action);}@@ -167,6 +192,16 @@ function _setJWT(store: IStore, next: Function, action: AnyAction) {features = context.tenant === tenant || tenant === '' ? features : {};}+ if (newUser.avatarURL) {+ const { knownAvatarUrl } = state['features/base/jwt'];++ if (knownAvatarUrl !== newUser.avatarURL) {+ store.dispatch(setDelayedLoadOfAvatarUrl(newUser.avatarURL));++ newUser.avatarURL = undefined;+ }+ }+_overwriteLocalParticipant(store, { ...newUser,features });diff --git a/react/features/base/jwt/reducer.ts b/react/features/base/jwt/reducer.tsindex d01fca6c4c..c27282900b 100644--- a/react/features/base/jwt/reducer.ts+++ b/react/features/base/jwt/reducer.ts@@ -1,14 +1,18 @@+import PersistenceRegistry from '../redux/PersistenceRegistry';import ReducerRegistry from '../redux/ReducerRegistry';import { equals } from '../redux/functions';-import { SET_JWT } from './actionTypes';+import { SET_DELAYED_LOAD_OF_AVATAR_URL, SET_JWT, SET_KNOWN_AVATAR_URL } from './actionTypes';+import logger from './logger';export interface IJwtState {callee?: {name: string;};+ delayedLoadOfAvatarUrl?: string;group?: string;jwt?: string;+ knownAvatarUrl?: string;server?: string;tenant?: string;user?: {@@ -17,6 +21,10 @@ export interface IJwtState {};}+PersistenceRegistry.register('features/base/jwt', {+ knownAvatarUrl: true+});+/*** Reduces redux actions which affect the JSON Web Token (JWT) stored in the* redux store.@@ -30,15 +38,35 @@ ReducerRegistry.register<IJwtState>('features/base/jwt',(state = {}, action): IJwtState => {switch (action.type) {+ case SET_DELAYED_LOAD_OF_AVATAR_URL: {+ const nextState = {+ ...state,+ delayedLoadOfAvatarUrl: action.avatarUrl+ };++ if (equals(state, nextState)) {+ return state;+ }++ logger.info('JWT avatarURL temporarily not loaded till jwt is verified on connect');++ return nextState;+ }case SET_JWT: {// eslint-disable-next-line @typescript-eslint/no-unused-varsconst { type, ...payload } = action;const nextState = {+ ...state,...payload};return equals(state, nextState) ? state : nextState;}+ case SET_KNOWN_AVATAR_URL:+ return {+ ...state,+ knownAvatarUrl: action.avatarUrl+ };}return state;