瀏覽代碼

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

j8
Vlad Piersec 4 年之前
父節點
當前提交
b02136d013

+ 14
- 0
react/features/base/jwt/functions.js 查看文件

1
 /* @flow */
1
 /* @flow */
2
 
2
 
3
+import jwtDecode from 'jwt-decode';
4
+
3
 import { parseURLParams } from '../util';
5
 import { parseURLParams } from '../util';
4
 
6
 
5
 /**
7
 /**
14
 export function parseJWTFromURLParams(url: URL = window.location) {
16
 export function parseJWTFromURLParams(url: URL = window.location) {
15
     return parseURLParams(url, true, 'search').jwt;
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
 // @flow
1
 // @flow
2
 import _ from 'lodash';
2
 import _ from 'lodash';
3
 
3
 
4
+import { PREJOIN_INITIALIZED } from '../../prejoin/actionTypes';
4
 import { APP_WILL_MOUNT } from '../app';
5
 import { APP_WILL_MOUNT } from '../app';
5
 import { setAudioOnly } from '../audio-only';
6
 import { setAudioOnly } from '../audio-only';
6
 import { SET_LOCATION_URL } from '../connection/actionTypes'; // minimize imports to avoid circular imports
7
 import { SET_LOCATION_URL } from '../connection/actionTypes'; // minimize imports to avoid circular imports
8
+import { getJwtName } from '../jwt/functions';
7
 import { getLocalParticipant, participantUpdated } from '../participants';
9
 import { getLocalParticipant, participantUpdated } from '../participants';
8
 import { MiddlewareRegistry } from '../redux';
10
 import { MiddlewareRegistry } from '../redux';
9
 import { parseURLParams } from '../util';
11
 import { parseURLParams } from '../util';
27
     case APP_WILL_MOUNT:
29
     case APP_WILL_MOUNT:
28
         _initializeCallIntegration(store);
30
         _initializeCallIntegration(store);
29
         break;
31
         break;
32
+    case PREJOIN_INITIALIZED: {
33
+        _maybeUpdateDisplayName(store);
34
+        break;
35
+    }
30
     case SETTINGS_UPDATED:
36
     case SETTINGS_UPDATED:
31
         _maybeHandleCallIntegrationChange(action);
37
         _maybeHandleCallIntegrationChange(action);
32
         _maybeSetAudioOnly(store, action);
38
         _maybeSetAudioOnly(store, action);
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
  * Updates the local participant according to settings changes.
145
  * Updates the local participant according to settings changes.
120
  *
146
  *

+ 5
- 0
react/features/prejoin/actionTypes.js 查看文件

4
  */
4
  */
5
 export const PREJOIN_START_CONFERENCE = 'PREJOIN_START_CONFERENCE';
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
  * Action type to set the status of the device.
13
  * Action type to set the status of the device.
9
  */
14
  */

+ 13
- 1
react/features/prejoin/actions.js 查看文件

18
 import { showErrorNotification } from '../notifications';
18
 import { showErrorNotification } from '../notifications';
19
 
19
 
20
 import {
20
 import {
21
+    PREJOIN_INITIALIZED,
21
     PREJOIN_START_CONFERENCE,
22
     PREJOIN_START_CONFERENCE,
22
     SET_DEVICE_STATUS,
23
     SET_DEVICE_STATUS,
23
     SET_DIALOUT_COUNTRY,
24
     SET_DIALOUT_COUNTRY,
195
 export function initPrejoin(tracks: Object[], errors: Object) {
196
 export function initPrejoin(tracks: Object[], errors: Object) {
196
     return async function(dispatch: Function) {
197
     return async function(dispatch: Function) {
197
         dispatch(setPrejoinDeviceErrors(errors));
198
         dispatch(setPrejoinDeviceErrors(errors));
198
-
199
+        dispatch(prejoinInitialized());
199
 
200
 
200
         tracks.forEach(track => dispatch(trackAdded(track)));
201
         tracks.forEach(track => dispatch(trackAdded(track)));
201
     };
202
     };
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
  * Creates a new audio track based on a device id and replaces the current one.
285
  * Creates a new audio track based on a device id and replaces the current one.
274
  *
286
  *

Loading…
取消
儲存