浏览代码

[RN] Reduce authentication actions

j8
Lyubo Marinov 8 年前
父节点
当前提交
266d8f72c5

+ 3
- 12
react/features/authentication/actionTypes.js 查看文件

@@ -38,22 +38,13 @@ export const STOP_WAIT_FOR_OWNER = Symbol('STOP_WAIT_FOR_OWNER');
38 38
  *
39 39
  * {
40 40
  *     type: UPGRADE_ROLE_FINISHED,
41
- *     error: Object
41
+ *     error: Object,
42
+ *     progress: number,
43
+ *     thenableWithCancel: Object
42 44
  * }
43 45
  */
44 46
 export const UPGRADE_ROLE_FINISHED = Symbol('UPGRADE_ROLE_FINISHED');
45 47
 
46
-/**
47
- * The type of (redux) action which informs that the authentication and role
48
- * upgrade process has finished the XMPP authentication part of the process
49
- * (which means that the XMPP credentials are OK).
50
- *
51
- * {
52
- *     type: UPGRADE_ROLE_LOGIN_ON
53
- * }
54
- */
55
-export const UPGRADE_ROLE_LOGIN_OK = Symbol('UPGRADE_ROLE_LOGIN_OK');
56
-
57 48
 /**
58 49
  * The type of (redux) action which signals that the process of authenticating
59 50
  * and upgrading the local participant's role has been started.

+ 29
- 15
react/features/authentication/actions.js 查看文件

@@ -8,7 +8,6 @@ import {
8 8
     CANCEL_WAIT_FOR_OWNER,
9 9
     STOP_WAIT_FOR_OWNER,
10 10
     UPGRADE_ROLE_FINISHED,
11
-    UPGRADE_ROLE_LOGIN_OK,
12 11
     UPGRADE_ROLE_STARTED,
13 12
     WAIT_FOR_OWNER
14 13
 } from './actionTypes';
@@ -42,20 +41,22 @@ export function authenticateAndUpgradeRole(
42 41
                 roomPassword,
43 42
 
44 43
                 onLoginSuccessful() {
45
-                    return dispatch({ type: UPGRADE_ROLE_LOGIN_OK });
44
+                    // When the login succeeds, the process has completed half
45
+                    // of its job (i.e. 0.5).
46
+                    return dispatch(_upgradeRoleFinished(process, 0.5));
46 47
                 }
47 48
             });
48 49
 
49 50
         dispatch(_upgradeRoleStarted(process));
50 51
         process.then(
51
-            /* onFulfilled */ () => dispatch(_upgradeRoleFinished()),
52
+            /* onFulfilled */ () => dispatch(_upgradeRoleFinished(process, 1)),
52 53
             /* onRejected */ error => {
53 54
                 // The lack of an error signals a cancellation.
54 55
                 if (error.authenticationError || error.connectionError) {
55 56
                     logger.error('authenticateAndUpgradeRole failed', error);
56 57
                 }
57 58
 
58
-                dispatch(_upgradeRoleFinished(error));
59
+                dispatch(_upgradeRoleFinished(process, error));
59 60
             });
60 61
 
61 62
         return process;
@@ -126,36 +127,49 @@ export function stopWaitForOwner() {
126 127
  * Signals that the process of authenticating and upgrading the local
127 128
  * participant's role has finished either with success or with a specific error.
128 129
  *
129
- * @param {Object} error - If <tt>undefined</tt>, then the process of
130
- * authenticating and upgrading the local participant's role has succeeded;
131
- * otherwise, it has failed with the specified error. Refer to
132
- * {@link JitsiConference#authenticateAndUpgradeRole} in lib-jitsi-meet for the
133
- * error details.
130
+ * @param {Object} thenableWithCancel - The process of authenticating and
131
+ * upgrading the local participant's role.
132
+ * @param {Object} progressOrError - If the value is a <tt>number</tt>, then the
133
+ * process of authenticating and upgrading the local participant's role has
134
+ * succeeded in one of its two/multiple steps; otherwise, it has failed with the
135
+ * specified error. Refer to {@link JitsiConference#authenticateAndUpgradeRole}
136
+ * in lib-jitsi-meet for the error details.
134 137
  * @private
135 138
  * @returns {{
136 139
  *     type: UPGRADE_ROLE_FINISHED,
137
- *     error: ?Object
140
+ *     error: ?Object,
141
+ *     progress: number
138 142
  * }}
139 143
  */
140
-function _upgradeRoleFinished(error: ?Object) {
141
-    if (error) {
144
+function _upgradeRoleFinished(
145
+        thenableWithCancel,
146
+        progressOrError: number | Object) {
147
+    let error;
148
+    let progress;
149
+
150
+    if (typeof progressOrError === 'number') {
151
+        progress = progressOrError;
152
+    } else {
142 153
         // Make the specified error object resemble an Error instance (to the
143 154
         // extent that jitsi-meet needs it).
144 155
         const {
145 156
             authenticationError,
146 157
             connectionError,
147 158
             ...other
148
-        } = error;
159
+        } = progressOrError;
149 160
 
150
-        error = { // eslint-disable-line no-param-reassign
161
+        error = {
151 162
             name: authenticationError || connectionError,
152 163
             ...other
153 164
         };
165
+        progress = authenticationError ? 0.5 : 0;
154 166
     }
155 167
 
156 168
     return {
157 169
         type: UPGRADE_ROLE_FINISHED,
158
-        error
170
+        error,
171
+        progress,
172
+        thenableWithCancel
159 173
     };
160 174
 }
161 175
 

+ 12
- 13
react/features/authentication/components/LoginDialog.native.js 查看文件

@@ -67,11 +67,10 @@ class LoginDialog extends Component {
67 67
         _error: PropTypes.object,
68 68
 
69 69
         /**
70
-         * Flag indicates that during the "upgrade role and authenticate"
71
-         * process the login part was successful and the next step is to obtain
72
-         * a session ID from Jicofo.
70
+         * The progress in the floating range between 0 and 1 of the
71
+         * authenticating and upgrading the role of the local participant/user.
73 72
          */
74
-        _upgradeRoleLoginOk: PropTypes.bool,
73
+        _progress: PropTypes.number,
75 74
 
76 75
         /**
77 76
          * Redux store dispatch method.
@@ -115,14 +114,14 @@ class LoginDialog extends Component {
115 114
         const {
116 115
             _connecting: connecting,
117 116
             _error: error,
118
-            _upgradeRoleLoginOk: upgradeRoleLoginOk,
117
+            _progress: progress,
119 118
             t
120 119
         } = this.props;
121 120
 
122 121
         let messageKey;
123 122
         let messageOptions;
124 123
 
125
-        if (upgradeRoleLoginOk) {
124
+        if (progress && progress < 1) {
126 125
             messageKey = 'connection.FETCH_SESSION_ID';
127 126
         } else if (error) {
128 127
             const { name } = error;
@@ -254,14 +253,14 @@ class LoginDialog extends Component {
254 253
  *     _configHosts: Object,
255 254
  *     _connecting: boolean,
256 255
  *     _error: Object,
257
- *     _upgradeRoleLoginOk: boolean
256
+ *     _progress: number
258 257
  * }}
259 258
  */
260 259
 function _mapStateToProps(state) {
261 260
     const {
262
-        upgradeRoleError,
263
-        upgradeRoleInProgress,
264
-        upgradeRoleLoginOk
261
+        error: authenticateAndUpgradeRoleError,
262
+        progress,
263
+        thenableWithCancel
265 264
     } = state['features/authentication'];
266 265
     const { authRequired } = state['features/base/conference'];
267 266
     const { hosts: configHosts } = state['features/base/config'];
@@ -273,9 +272,9 @@ function _mapStateToProps(state) {
273 272
     return {
274 273
         _conference: authRequired,
275 274
         _configHosts: configHosts,
276
-        _connecting: Boolean(connecting) || Boolean(upgradeRoleInProgress),
277
-        _error: connectionError || upgradeRoleError,
278
-        _upgradeRoleLoginOk: upgradeRoleLoginOk
275
+        _connecting: Boolean(connecting) || Boolean(thenableWithCancel),
276
+        _error: connectionError || authenticateAndUpgradeRoleError,
277
+        _progress: progress
279 278
     };
280 279
 }
281 280
 

+ 3
- 3
react/features/authentication/middleware.js 查看文件

@@ -38,10 +38,10 @@ import { LoginDialog, WaitForOwnerDialog } from './components';
38 38
 MiddlewareRegistry.register(store => next => action => {
39 39
     switch (action.type) {
40 40
     case CANCEL_LOGIN: {
41
-        const { upgradeRoleInProgress }
41
+        const { thenableWithCancel }
42 42
             = store.getState()['features/authentication'];
43 43
 
44
-        upgradeRoleInProgress && upgradeRoleInProgress.cancel();
44
+        thenableWithCancel && thenableWithCancel.cancel();
45 45
 
46 46
         // The LoginDialog can be opened on top of "wait for owner". The app
47 47
         // should navigate only if LoginDialog was open without the
@@ -117,7 +117,7 @@ MiddlewareRegistry.register(store => next => action => {
117 117
         action.waitForOwnerTimeoutID = setTimeout(handler, timeoutMs);
118 118
 
119 119
         // The WAIT_FOR_OWNER action is cyclic and we don't want to hide the
120
-        // login dialog every few seconds...
120
+        // login dialog every few seconds.
121 121
         isDialogOpen(store, LoginDialog)
122 122
             || store.dispatch(_openWaitForOwnerDialog());
123 123
         break;

+ 30
- 14
react/features/authentication/reducer.js 查看文件

@@ -6,7 +6,6 @@ import {
6 6
     CANCEL_LOGIN,
7 7
     STOP_WAIT_FOR_OWNER,
8 8
     UPGRADE_ROLE_FINISHED,
9
-    UPGRADE_ROLE_LOGIN_OK,
10 9
     UPGRADE_ROLE_STARTED,
11 10
     WAIT_FOR_OWNER
12 11
 } from './actionTypes';
@@ -15,28 +14,45 @@ ReducerRegistry.register('features/authentication', (state = {}, action) => {
15 14
     switch (action.type) {
16 15
     case CANCEL_LOGIN:
17 16
         return assign(state, {
18
-            upgradeRoleError: undefined,
19
-            upgradeRoleInProgress: undefined,
20
-            upgradeRoleLoginOk: false
17
+            error: undefined,
18
+            progress: undefined,
19
+            thenableWithCancel: undefined
21 20
         });
22 21
 
23 22
     case STOP_WAIT_FOR_OWNER:
24 23
         return assign(state, {
25
-            upgradeRoleError: undefined,
24
+            error: undefined,
26 25
             waitForOwnerTimeoutID: undefined
27 26
         });
28 27
 
29
-    case UPGRADE_ROLE_FINISHED:
30
-    case UPGRADE_ROLE_STARTED:
31
-        return assign(state, {
32
-            upgradeRoleError: action.error,
33
-            upgradeRoleInProgress: action.thenableWithCancel,
34
-            upgradeRoleLoginOk: false
35
-        });
28
+    case UPGRADE_ROLE_FINISHED: {
29
+        let { thenableWithCancel } = action;
30
+
31
+        if (state.thenableWithCancel === thenableWithCancel) {
32
+            const { error, progress } = action;
36 33
 
37
-    case UPGRADE_ROLE_LOGIN_OK:
34
+            // An error interrupts the process of authenticating and upgrading
35
+            // the role of the local participant/user i.e. the process is no
36
+            // more. Obviously, the process seizes to exist also when it does
37
+            // its whole job.
38
+            if (error || progress === 1) {
39
+                thenableWithCancel = undefined;
40
+            }
41
+
42
+            return assign(state, {
43
+                error,
44
+                progress: progress || undefined,
45
+                thenableWithCancel
46
+            });
47
+        }
48
+        break;
49
+    }
50
+
51
+    case UPGRADE_ROLE_STARTED:
38 52
         return assign(state, {
39
-            upgradeRoleLoginOk: true
53
+            error: undefined,
54
+            progress: undefined,
55
+            thenableWithCancel: action.thenableWithCancel
40 56
         });
41 57
 
42 58
     case WAIT_FOR_OWNER:

正在加载...
取消
保存