feat(prejoin): Add name from jwt to prejoin screen
This commit is contained in:
parent
734631a7a4
commit
b02136d013
|
@ -1,5 +1,7 @@
|
|||
/* @flow */
|
||||
|
||||
import jwtDecode from 'jwt-decode';
|
||||
|
||||
import { parseURLParams } from '../util';
|
||||
|
||||
/**
|
||||
|
@ -14,3 +16,15 @@ import { parseURLParams } from '../util';
|
|||
export function parseJWTFromURLParams(url: URL = window.location) {
|
||||
return parseURLParams(url, true, 'search').jwt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user name after decoding the jwt.
|
||||
*
|
||||
* @param {Object} state - The app state.
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getJwtName(state: Object) {
|
||||
const jwtData = jwtDecode(state['features/base/jwt'].jwt);
|
||||
|
||||
return jwtData?.context?.user?.name || '';
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
// @flow
|
||||
import _ from 'lodash';
|
||||
|
||||
import { PREJOIN_INITIALIZED } from '../../prejoin/actionTypes';
|
||||
import { APP_WILL_MOUNT } from '../app';
|
||||
import { setAudioOnly } from '../audio-only';
|
||||
import { SET_LOCATION_URL } from '../connection/actionTypes'; // minimize imports to avoid circular imports
|
||||
import { getJwtName } from '../jwt/functions';
|
||||
import { getLocalParticipant, participantUpdated } from '../participants';
|
||||
import { MiddlewareRegistry } from '../redux';
|
||||
import { parseURLParams } from '../util';
|
||||
|
@ -27,6 +29,10 @@ MiddlewareRegistry.register(store => next => action => {
|
|||
case APP_WILL_MOUNT:
|
||||
_initializeCallIntegration(store);
|
||||
break;
|
||||
case PREJOIN_INITIALIZED: {
|
||||
_maybeUpdateDisplayName(store);
|
||||
break;
|
||||
}
|
||||
case SETTINGS_UPDATED:
|
||||
_maybeHandleCallIntegrationChange(action);
|
||||
_maybeSetAudioOnly(store, action);
|
||||
|
@ -115,6 +121,26 @@ function _maybeSetAudioOnly(
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the display name to the one in JWT if there is one.
|
||||
*
|
||||
* @param {Store} store - The redux store.
|
||||
* @private
|
||||
* @returns {void}
|
||||
*/
|
||||
function _maybeUpdateDisplayName({ dispatch, getState }) {
|
||||
const state = getState();
|
||||
const hasJwt = Boolean(state['features/base/jwt'].jwt);
|
||||
|
||||
if (hasJwt) {
|
||||
const displayName = getJwtName(state);
|
||||
|
||||
dispatch(updateSettings({
|
||||
displayName
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the local participant according to settings changes.
|
||||
*
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
*/
|
||||
export const PREJOIN_START_CONFERENCE = 'PREJOIN_START_CONFERENCE';
|
||||
|
||||
/**
|
||||
* Action type to signal that prejoin page was initialized.
|
||||
*/
|
||||
export const PREJOIN_INITIALIZED = 'PREJOIN_INITIALIZED';
|
||||
|
||||
/**
|
||||
* Action type to set the status of the device.
|
||||
*/
|
||||
|
|
|
@ -18,6 +18,7 @@ import { executeDialOutRequest, executeDialOutStatusRequest, getDialInfoPageURL
|
|||
import { showErrorNotification } from '../notifications';
|
||||
|
||||
import {
|
||||
PREJOIN_INITIALIZED,
|
||||
PREJOIN_START_CONFERENCE,
|
||||
SET_DEVICE_STATUS,
|
||||
SET_DIALOUT_COUNTRY,
|
||||
|
@ -195,7 +196,7 @@ export function dialOut(onSuccess: Function, onFail: Function) {
|
|||
export function initPrejoin(tracks: Object[], errors: Object) {
|
||||
return async function(dispatch: Function) {
|
||||
dispatch(setPrejoinDeviceErrors(errors));
|
||||
|
||||
dispatch(prejoinInitialized());
|
||||
|
||||
tracks.forEach(track => dispatch(trackAdded(track)));
|
||||
};
|
||||
|
@ -269,6 +270,17 @@ export function openDialInPage() {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Action used to signal that the prejoin page has been initialized.
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
function prejoinInitialized() {
|
||||
return {
|
||||
type: PREJOIN_INITIALIZED
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new audio track based on a device id and replaces the current one.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue