Browse Source

[RN] Reduce authentication actions

j8
Lyubo Marinov 8 years ago
parent
commit
266d8f72c5

+ 3
- 12
react/features/authentication/actionTypes.js View File

38
  *
38
  *
39
  * {
39
  * {
40
  *     type: UPGRADE_ROLE_FINISHED,
40
  *     type: UPGRADE_ROLE_FINISHED,
41
- *     error: Object
41
+ *     error: Object,
42
+ *     progress: number,
43
+ *     thenableWithCancel: Object
42
  * }
44
  * }
43
  */
45
  */
44
 export const UPGRADE_ROLE_FINISHED = Symbol('UPGRADE_ROLE_FINISHED');
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
  * The type of (redux) action which signals that the process of authenticating
49
  * The type of (redux) action which signals that the process of authenticating
59
  * and upgrading the local participant's role has been started.
50
  * and upgrading the local participant's role has been started.

+ 29
- 15
react/features/authentication/actions.js View File

8
     CANCEL_WAIT_FOR_OWNER,
8
     CANCEL_WAIT_FOR_OWNER,
9
     STOP_WAIT_FOR_OWNER,
9
     STOP_WAIT_FOR_OWNER,
10
     UPGRADE_ROLE_FINISHED,
10
     UPGRADE_ROLE_FINISHED,
11
-    UPGRADE_ROLE_LOGIN_OK,
12
     UPGRADE_ROLE_STARTED,
11
     UPGRADE_ROLE_STARTED,
13
     WAIT_FOR_OWNER
12
     WAIT_FOR_OWNER
14
 } from './actionTypes';
13
 } from './actionTypes';
42
                 roomPassword,
41
                 roomPassword,
43
 
42
 
44
                 onLoginSuccessful() {
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
         dispatch(_upgradeRoleStarted(process));
50
         dispatch(_upgradeRoleStarted(process));
50
         process.then(
51
         process.then(
51
-            /* onFulfilled */ () => dispatch(_upgradeRoleFinished()),
52
+            /* onFulfilled */ () => dispatch(_upgradeRoleFinished(process, 1)),
52
             /* onRejected */ error => {
53
             /* onRejected */ error => {
53
                 // The lack of an error signals a cancellation.
54
                 // The lack of an error signals a cancellation.
54
                 if (error.authenticationError || error.connectionError) {
55
                 if (error.authenticationError || error.connectionError) {
55
                     logger.error('authenticateAndUpgradeRole failed', error);
56
                     logger.error('authenticateAndUpgradeRole failed', error);
56
                 }
57
                 }
57
 
58
 
58
-                dispatch(_upgradeRoleFinished(error));
59
+                dispatch(_upgradeRoleFinished(process, error));
59
             });
60
             });
60
 
61
 
61
         return process;
62
         return process;
126
  * Signals that the process of authenticating and upgrading the local
127
  * Signals that the process of authenticating and upgrading the local
127
  * participant's role has finished either with success or with a specific error.
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
  * @private
137
  * @private
135
  * @returns {{
138
  * @returns {{
136
  *     type: UPGRADE_ROLE_FINISHED,
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
         // Make the specified error object resemble an Error instance (to the
153
         // Make the specified error object resemble an Error instance (to the
143
         // extent that jitsi-meet needs it).
154
         // extent that jitsi-meet needs it).
144
         const {
155
         const {
145
             authenticationError,
156
             authenticationError,
146
             connectionError,
157
             connectionError,
147
             ...other
158
             ...other
148
-        } = error;
159
+        } = progressOrError;
149
 
160
 
150
-        error = { // eslint-disable-line no-param-reassign
161
+        error = {
151
             name: authenticationError || connectionError,
162
             name: authenticationError || connectionError,
152
             ...other
163
             ...other
153
         };
164
         };
165
+        progress = authenticationError ? 0.5 : 0;
154
     }
166
     }
155
 
167
 
156
     return {
168
     return {
157
         type: UPGRADE_ROLE_FINISHED,
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 View File

67
         _error: PropTypes.object,
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
          * Redux store dispatch method.
76
          * Redux store dispatch method.
115
         const {
114
         const {
116
             _connecting: connecting,
115
             _connecting: connecting,
117
             _error: error,
116
             _error: error,
118
-            _upgradeRoleLoginOk: upgradeRoleLoginOk,
117
+            _progress: progress,
119
             t
118
             t
120
         } = this.props;
119
         } = this.props;
121
 
120
 
122
         let messageKey;
121
         let messageKey;
123
         let messageOptions;
122
         let messageOptions;
124
 
123
 
125
-        if (upgradeRoleLoginOk) {
124
+        if (progress && progress < 1) {
126
             messageKey = 'connection.FETCH_SESSION_ID';
125
             messageKey = 'connection.FETCH_SESSION_ID';
127
         } else if (error) {
126
         } else if (error) {
128
             const { name } = error;
127
             const { name } = error;
254
  *     _configHosts: Object,
253
  *     _configHosts: Object,
255
  *     _connecting: boolean,
254
  *     _connecting: boolean,
256
  *     _error: Object,
255
  *     _error: Object,
257
- *     _upgradeRoleLoginOk: boolean
256
+ *     _progress: number
258
  * }}
257
  * }}
259
  */
258
  */
260
 function _mapStateToProps(state) {
259
 function _mapStateToProps(state) {
261
     const {
260
     const {
262
-        upgradeRoleError,
263
-        upgradeRoleInProgress,
264
-        upgradeRoleLoginOk
261
+        error: authenticateAndUpgradeRoleError,
262
+        progress,
263
+        thenableWithCancel
265
     } = state['features/authentication'];
264
     } = state['features/authentication'];
266
     const { authRequired } = state['features/base/conference'];
265
     const { authRequired } = state['features/base/conference'];
267
     const { hosts: configHosts } = state['features/base/config'];
266
     const { hosts: configHosts } = state['features/base/config'];
273
     return {
272
     return {
274
         _conference: authRequired,
273
         _conference: authRequired,
275
         _configHosts: configHosts,
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 View File

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

+ 30
- 14
react/features/authentication/reducer.js View File

6
     CANCEL_LOGIN,
6
     CANCEL_LOGIN,
7
     STOP_WAIT_FOR_OWNER,
7
     STOP_WAIT_FOR_OWNER,
8
     UPGRADE_ROLE_FINISHED,
8
     UPGRADE_ROLE_FINISHED,
9
-    UPGRADE_ROLE_LOGIN_OK,
10
     UPGRADE_ROLE_STARTED,
9
     UPGRADE_ROLE_STARTED,
11
     WAIT_FOR_OWNER
10
     WAIT_FOR_OWNER
12
 } from './actionTypes';
11
 } from './actionTypes';
15
     switch (action.type) {
14
     switch (action.type) {
16
     case CANCEL_LOGIN:
15
     case CANCEL_LOGIN:
17
         return assign(state, {
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
     case STOP_WAIT_FOR_OWNER:
22
     case STOP_WAIT_FOR_OWNER:
24
         return assign(state, {
23
         return assign(state, {
25
-            upgradeRoleError: undefined,
24
+            error: undefined,
26
             waitForOwnerTimeoutID: undefined
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
         return assign(state, {
52
         return assign(state, {
39
-            upgradeRoleLoginOk: true
53
+            error: undefined,
54
+            progress: undefined,
55
+            thenableWithCancel: action.thenableWithCancel
40
         });
56
         });
41
 
57
 
42
     case WAIT_FOR_OWNER:
58
     case WAIT_FOR_OWNER:

Loading…
Cancel
Save