Просмотр исходного кода

feat(prejoin): Add name from jwt to prejoin screen

j8
Vlad Piersec 4 лет назад
Родитель
Сommit
b02136d013

+ 14
- 0
react/features/base/jwt/functions.js Просмотреть файл

@@ -1,5 +1,7 @@
1 1
 /* @flow */
2 2
 
3
+import jwtDecode from 'jwt-decode';
4
+
3 5
 import { parseURLParams } from '../util';
4 6
 
5 7
 /**
@@ -14,3 +16,15 @@ import { parseURLParams } from '../util';
14 16
 export function parseJWTFromURLParams(url: URL = window.location) {
15 17
     return parseURLParams(url, true, 'search').jwt;
16 18
 }
19
+
20
+/**
21
+ * Returns the user name after decoding the jwt.
22
+ *
23
+ * @param {Object} state - The app state.
24
+ * @returns {string}
25
+ */
26
+export function getJwtName(state: Object) {
27
+    const jwtData = jwtDecode(state['features/base/jwt'].jwt);
28
+
29
+    return jwtData?.context?.user?.name || '';
30
+}

+ 26
- 0
react/features/base/settings/middleware.js Просмотреть файл

@@ -1,9 +1,11 @@
1 1
 // @flow
2 2
 import _ from 'lodash';
3 3
 
4
+import { PREJOIN_INITIALIZED } from '../../prejoin/actionTypes';
4 5
 import { APP_WILL_MOUNT } from '../app';
5 6
 import { setAudioOnly } from '../audio-only';
6 7
 import { SET_LOCATION_URL } from '../connection/actionTypes'; // minimize imports to avoid circular imports
8
+import { getJwtName } from '../jwt/functions';
7 9
 import { getLocalParticipant, participantUpdated } from '../participants';
8 10
 import { MiddlewareRegistry } from '../redux';
9 11
 import { parseURLParams } from '../util';
@@ -27,6 +29,10 @@ MiddlewareRegistry.register(store => next => action => {
27 29
     case APP_WILL_MOUNT:
28 30
         _initializeCallIntegration(store);
29 31
         break;
32
+    case PREJOIN_INITIALIZED: {
33
+        _maybeUpdateDisplayName(store);
34
+        break;
35
+    }
30 36
     case SETTINGS_UPDATED:
31 37
         _maybeHandleCallIntegrationChange(action);
32 38
         _maybeSetAudioOnly(store, action);
@@ -115,6 +121,26 @@ function _maybeSetAudioOnly(
115 121
     }
116 122
 }
117 123
 
124
+/**
125
+ * Updates the display name to the one in JWT if there is one.
126
+ *
127
+ * @param {Store} store - The redux store.
128
+ * @private
129
+ * @returns {void}
130
+ */
131
+function _maybeUpdateDisplayName({ dispatch, getState }) {
132
+    const state = getState();
133
+    const hasJwt = Boolean(state['features/base/jwt'].jwt);
134
+
135
+    if (hasJwt) {
136
+        const displayName = getJwtName(state);
137
+
138
+        dispatch(updateSettings({
139
+            displayName
140
+        }));
141
+    }
142
+}
143
+
118 144
 /**
119 145
  * Updates the local participant according to settings changes.
120 146
  *

+ 5
- 0
react/features/prejoin/actionTypes.js Просмотреть файл

@@ -4,6 +4,11 @@
4 4
  */
5 5
 export const PREJOIN_START_CONFERENCE = 'PREJOIN_START_CONFERENCE';
6 6
 
7
+/**
8
+ * Action type to signal that prejoin page was initialized.
9
+ */
10
+export const PREJOIN_INITIALIZED = 'PREJOIN_INITIALIZED';
11
+
7 12
 /**
8 13
  * Action type to set the status of the device.
9 14
  */

+ 13
- 1
react/features/prejoin/actions.js Просмотреть файл

@@ -18,6 +18,7 @@ import { executeDialOutRequest, executeDialOutStatusRequest, getDialInfoPageURL
18 18
 import { showErrorNotification } from '../notifications';
19 19
 
20 20
 import {
21
+    PREJOIN_INITIALIZED,
21 22
     PREJOIN_START_CONFERENCE,
22 23
     SET_DEVICE_STATUS,
23 24
     SET_DIALOUT_COUNTRY,
@@ -195,7 +196,7 @@ export function dialOut(onSuccess: Function, onFail: Function) {
195 196
 export function initPrejoin(tracks: Object[], errors: Object) {
196 197
     return async function(dispatch: Function) {
197 198
         dispatch(setPrejoinDeviceErrors(errors));
198
-
199
+        dispatch(prejoinInitialized());
199 200
 
200 201
         tracks.forEach(track => dispatch(trackAdded(track)));
201 202
     };
@@ -269,6 +270,17 @@ export function openDialInPage() {
269 270
     };
270 271
 }
271 272
 
273
+/**
274
+ * Action used to signal that the prejoin page has been initialized.
275
+ *
276
+ * @returns {Object}
277
+ */
278
+function prejoinInitialized() {
279
+    return {
280
+        type: PREJOIN_INITIALIZED
281
+    };
282
+}
283
+
272 284
 /**
273 285
  * Creates a new audio track based on a device id and replaces the current one.
274 286
  *

Загрузка…
Отмена
Сохранить