Browse Source

feat(xmpp): credentials in CONNECTION_FAILED

Include XMPP user's credentials in the
CONNECTION_FAILED/PASSWORD_REQUIRED error event.
dev1
paweldomas 8 years ago
parent
commit
04ee706db7
2 changed files with 37 additions and 15 deletions
  1. 8
    1
      authenticateAndUpgradeRole.js
  2. 29
    14
      modules/xmpp/xmpp.js

+ 8
- 1
authenticateAndUpgradeRole.js View File

@@ -15,6 +15,12 @@ import XMPP from './modules/xmpp/xmpp';
15 15
  * returned by Jicofo on authentication attempt. See
16 16
  * {@link https://xmpp.org/rfcs/rfc3920.html#streams-error}.
17 17
  * @property {String} [message] - More details about the error.
18
+ * @property {Object} [credentials] - The credentials that failed the
19
+ * authentication.
20
+ * @property {String} [credentials.jid] - The XMPP ID part of the credentials
21
+ * that failed the authentication.
22
+ * @property {string} [credentials.password] - The password part of the
23
+ * credentials that failed the authentication.
18 24
  *
19 25
  * NOTE If neither one of the errors is present, then the operation has been
20 26
  * canceled.
@@ -119,9 +125,10 @@ export default function authenticateAndUpgradeRole({
119 125
             });
120 126
         xmpp.addListener(
121 127
             CONNECTION_FAILED,
122
-            (connectionError, message) => {
128
+            (connectionError, message, credentials) => {
123 129
                 reject({
124 130
                     connectionError,
131
+                    credentials,
125 132
                     message
126 133
                 });
127 134
                 xmpp = undefined;

+ 29
- 14
modules/xmpp/xmpp.js View File

@@ -119,11 +119,16 @@ export default class XMPP extends Listenable {
119 119
 
120 120
     /**
121 121
      * Receive connection status changes and handles them.
122
-     * @password {string} the password passed in connect method
123
-     * @status the connection status
124
-     * @msg message
122
+     *
123
+     * @param {Object} credentials
124
+     * @param {string} credentials.jid - The user's XMPP ID passed to the
125
+     * connect method. For example, 'user@xmpp.com'.
126
+     * @param {string} credentials.password - The password passed to the connect
127
+     * method.
128
+     * @param {string} status - One of Strophe's connection status strings.
129
+     * @param {string} [msg] - The connection error message provided by Strophe.
125 130
      */
126
-    connectionHandler(password, status, msg) {
131
+    connectionHandler(credentials = {}, status, msg) {
127 132
         const now = window.performance.now();
128 133
         const statusStr = Strophe.getStatusString(status).toLowerCase();
129 134
 
@@ -153,7 +158,7 @@ export default class XMPP extends Listenable {
153 158
                     }
154 159
                 });
155 160
 
156
-            if (password) {
161
+            if (credentials.password) {
157 162
                 this.authenticatedUser = true;
158 163
             }
159 164
             if (this.connection && this.connection.connected
@@ -175,7 +180,7 @@ export default class XMPP extends Listenable {
175 180
             // Stop ping interval
176 181
             this.connection.ping.stopInterval();
177 182
             const wasIntentionalDisconnect = this.disconnectInProgress;
178
-            const errMsg = msg ? msg : this.lastErrorMsg;
183
+            const errMsg = msg || this.lastErrorMsg;
179 184
 
180 185
             this.disconnectInProgress = false;
181 186
             if (this.anonymousConnectionFailed) {
@@ -206,19 +211,21 @@ export default class XMPP extends Listenable {
206 211
                     this.eventEmitter.emit(
207 212
                         JitsiConnectionEvents.CONNECTION_FAILED,
208 213
                         JitsiConnectionErrors.SERVER_ERROR,
209
-                        errMsg ? errMsg : 'server-error');
214
+                        errMsg || 'server-error');
210 215
                 } else {
211 216
                     this.eventEmitter.emit(
212 217
                         JitsiConnectionEvents.CONNECTION_FAILED,
213 218
                         JitsiConnectionErrors.CONNECTION_DROPPED_ERROR,
214
-                        errMsg ? errMsg : 'connection-dropped-error');
219
+                        errMsg || 'connection-dropped-error');
215 220
                 }
216 221
             }
217 222
         } else if (status === Strophe.Status.AUTHFAIL) {
218 223
             // wrong password or username, prompt user
219
-            this.eventEmitter.emit(JitsiConnectionEvents.CONNECTION_FAILED,
220
-                JitsiConnectionErrors.PASSWORD_REQUIRED);
221
-
224
+            this.eventEmitter.emit(
225
+                JitsiConnectionEvents.CONNECTION_FAILED,
226
+                JitsiConnectionErrors.PASSWORD_REQUIRED,
227
+                msg,
228
+                credentials);
222 229
         }
223 230
     }
224 231
 
@@ -258,8 +265,13 @@ export default class XMPP extends Listenable {
258 265
         this.anonymousConnectionFailed = false;
259 266
         this.connectionFailed = false;
260 267
         this.lastErrorMsg = undefined;
261
-        this.connection.connect(jid, password,
262
-            this.connectionHandler.bind(this, password));
268
+        this.connection.connect(
269
+            jid,
270
+            password,
271
+            this.connectionHandler.bind(this, {
272
+                jid,
273
+                password
274
+            }));
263 275
     }
264 276
 
265 277
     /**
@@ -275,7 +287,10 @@ export default class XMPP extends Listenable {
275 287
         logger.log(`(TIME) Strophe Attaching\t:${now}`);
276 288
         this.connection.attach(options.jid, options.sid,
277 289
             parseInt(options.rid, 10) + 1,
278
-            this.connectionHandler.bind(this, options.password));
290
+            this.connectionHandler.bind(this, {
291
+                jid: options.jid,
292
+                password: options.password
293
+            }));
279 294
     }
280 295
 
281 296
     /**

Loading…
Cancel
Save