瀏覽代碼

feat(moderator): Make sure we resolve the sendConference promise.

release-8443
damencho 1 年之前
父節點
當前提交
83ba892106
共有 4 個檔案被更改,包括 45 行新增18 行删除
  1. 6
    1
      JitsiConnection.js
  2. 7
    1
      authenticateAndUpgradeRole.js
  3. 2
    1
      modules/xmpp/ChatRoom.js
  4. 30
    15
      modules/xmpp/moderator.js

+ 6
- 1
JitsiConnection.js 查看文件

@@ -1,3 +1,5 @@
1
+import { getLogger } from '@jitsi/logger';
2
+
1 3
 import JitsiConference from './JitsiConference';
2 4
 import * as JitsiConnectionEvents from './JitsiConnectionEvents';
3 5
 import FeatureFlags from './modules/flags/FeatureFlags';
@@ -8,6 +10,8 @@ import {
8 10
     createConnectionFailedEvent
9 11
 } from './service/statistics/AnalyticsEvents';
10 12
 
13
+const logger = getLogger(__filename);
14
+
11 15
 /**
12 16
  * Creates a new connection object for the Jitsi Meet server side video
13 17
  * conferencing service. Provides access to the JitsiConference interface.
@@ -67,7 +71,8 @@ JitsiConnection.prototype.connect = function(options = {}) {
67 71
         this.xmpp.moderator.sendConferenceRequest(this.xmpp.getRoomJid(options.name))
68 72
             .then(() => {
69 73
                 this.xmpp.connect(options.id, options.password);
70
-            });
74
+            })
75
+            .catch(e => logger.trace('sendConferenceRequest rejected', e));
71 76
     } else {
72 77
         this.xmpp.connect(options.id, options.password);
73 78
     }

+ 7
- 1
authenticateAndUpgradeRole.js 查看文件

@@ -1,3 +1,5 @@
1
+import { getLogger } from '@jitsi/logger';
2
+
1 3
 import {
2 4
     CONNECTION_DISCONNECTED,
3 5
     CONNECTION_ESTABLISHED,
@@ -5,6 +7,8 @@ import {
5 7
 } from './JitsiConnectionEvents';
6 8
 import XMPP from './modules/xmpp/xmpp';
7 9
 
10
+const logger = getLogger(__filename);
11
+
8 12
 /**
9 13
  * @typedef {Object} UpgradeRoleError
10 14
  *
@@ -111,7 +115,9 @@ export default function authenticateAndUpgradeRole({
111 115
                         // we execute this logic in JitsiConference where we bind the current conference as `this`
112 116
                         // At this point we should have the new session ID
113 117
                         // stored in the settings. Send a new conference IQ.
114
-                        this.room.xmpp.moderator.sendConferenceRequest(this.room.roomjid).finally(resolve);
118
+                        this.room.xmpp.moderator.sendConferenceRequest(this.room.roomjid)
119
+                            .catch(e => logger.trace('sendConferenceRequest rejected', e))
120
+                            .finally(resolve);
115 121
                     })
116 122
                     .catch(({ error, message }) => {
117 123
                         xmpp.disconnect();

+ 2
- 1
modules/xmpp/ChatRoom.js 查看文件

@@ -249,7 +249,8 @@ export default class ChatRoom extends Listenable {
249 249
                         this.onConnStatusChanged.bind(this))
250 250
                 );
251 251
                 resolve();
252
-            });
252
+            })
253
+            .catch(e => logger.trace('PreJoin rejected', e));
253 254
         });
254 255
     }
255 256
 

+ 30
- 15
modules/xmpp/moderator.js 查看文件

@@ -304,14 +304,14 @@ export default class Moderator extends Listenable {
304 304
         // to mark whether we have already sent a conference request
305 305
         this.conferenceRequestSent = false;
306 306
 
307
-        return new Promise(resolve => {
307
+        return new Promise((resolve, reject) => {
308 308
             if (this.mode === 'xmpp') {
309 309
                 logger.info(`Sending conference request over XMPP to ${this.targetJid}`);
310 310
 
311 311
                 this.connection.sendIQ(
312 312
                     this._createConferenceIq(roomJid),
313
-                    result => this._handleIqSuccess(roomJid, result, resolve),
314
-                    error => this._handleIqError(roomJid, error, resolve));
313
+                    result => this._handleIqSuccess(roomJid, result, resolve, reject),
314
+                    error => this._handleIqError(roomJid, error, resolve, reject));
315 315
 
316 316
                 // XXX We're pressed for time here because we're beginning a complex
317 317
                 // and/or lengthy conference-establishment process which supposedly
@@ -335,11 +335,11 @@ export default class Moderator extends Listenable {
335 335
                                         && text.indexOf('400 invalid-session') > 0;
336 336
                                     const notAuthorized = response.status === 403;
337 337
 
338
-                                    this._handleError(roomJid, sessionError, notAuthorized, resolve);
338
+                                    this._handleError(roomJid, sessionError, notAuthorized, resolve, reject);
339 339
                                 })
340 340
                                 .catch(error => {
341 341
                                     logger.warn(`Error: ${error}`);
342
-                                    this._handleError(roomJid);
342
+                                    this._handleError(roomJid, undefined, undefined, resolve, reject);
343 343
                                 });
344 344
 
345 345
                             // _handleError has either scheduled a retry or fired an event indicating failure.
@@ -347,12 +347,12 @@ export default class Moderator extends Listenable {
347 347
                         }
348 348
                         response.json()
349 349
                             .then(resultJson => {
350
-                                this._handleSuccess(roomJid, resultJson, resolve);
350
+                                this._handleSuccess(roomJid, resultJson, resolve, reject);
351 351
                             });
352 352
                     })
353 353
                     .catch(error => {
354 354
                         logger.warn(`Error: ${error}`);
355
-                        this._handleError(roomJid);
355
+                        this._handleError(roomJid, undefined, undefined, resolve, reject);
356 356
                     });
357 357
             }
358 358
         }).then(() => {
@@ -365,9 +365,10 @@ export default class Moderator extends Listenable {
365 365
      * @param roomJid
366 366
      * @param conferenceRequest
367 367
      * @param callback
368
+     * @param errorCallback
368 369
      * @private
369 370
      */
370
-    _handleSuccess(roomJid, conferenceRequest, callback) {
371
+    _handleSuccess(roomJid, conferenceRequest, callback, errorCallback) {
371 372
         // Reset the error timeout (because we haven't failed here).
372 373
         this.getNextErrorTimeout(true);
373 374
 
@@ -400,6 +401,8 @@ export default class Moderator extends Listenable {
400 401
 
401 402
             this.xmpp.eventEmitter.emit(CONNECTION_FAILED, NOT_LIVE_ERROR);
402 403
 
404
+            errorCallback();
405
+
403 406
             return;
404 407
         }
405 408
 
@@ -413,6 +416,8 @@ export default class Moderator extends Listenable {
413 416
 
414 417
                 this.xmpp.eventEmitter.emit(CONNECTION_REDIRECTED, conferenceRequest.vnode, conferenceRequest.focusJid);
415 418
 
419
+                errorCallback();
420
+
416 421
                 return;
417 422
             }
418 423
 
@@ -425,7 +430,7 @@ export default class Moderator extends Listenable {
425 430
             logger.info(`Not ready yet, will retry in ${waitMs} ms.`);
426 431
             window.setTimeout(
427 432
                 () => this.sendConferenceRequest(roomJid)
428
-                    .then(callback),
433
+                    .then(callback).catch(errorCallback),
429 434
                 waitMs);
430 435
         }
431 436
     }
@@ -436,9 +441,10 @@ export default class Moderator extends Listenable {
436 441
      * @param sessionError
437 442
      * @param notAuthorized
438 443
      * @param callback
444
+     * @param errorCallback
439 445
      * @private
440 446
      */
441
-    _handleError(roomJid, sessionError, notAuthorized, callback) {
447
+    _handleError(roomJid, sessionError, notAuthorized, callback, errorCallback) { // eslint-disable-line max-params
442 448
         // If the session is invalid, remove and try again without session ID to get
443 449
         // a new one
444 450
         if (sessionError) {
@@ -451,6 +457,8 @@ export default class Moderator extends Listenable {
451 457
             logger.warn('Unauthorized to start the conference');
452 458
             this.eventEmitter.emit(XMPPEvents.AUTHENTICATION_REQUIRED);
453 459
 
460
+            errorCallback();
461
+
454 462
             return;
455 463
         }
456 464
 
@@ -461,13 +469,16 @@ export default class Moderator extends Listenable {
461 469
             logger.info(`Invalid session, will retry after ${waitMs} ms.`);
462 470
             this.getNextTimeout(true);
463 471
             window.setTimeout(() => this.sendConferenceRequest(roomJid)
464
-                .then(callback), waitMs);
472
+                .then(callback)
473
+                .catch(errorCallback), waitMs);
465 474
         } else {
466 475
             logger.error('Failed to get a successful response, giving up.');
467 476
 
468 477
             // This is a "fatal" error and the user of the lib should handle it accordingly.
469 478
             // TODO: change the event name to something accurate.
470 479
             this.eventEmitter.emit(XMPPEvents.FOCUS_DISCONNECTED);
480
+
481
+            errorCallback();
471 482
         }
472 483
     }
473 484
 
@@ -478,8 +489,9 @@ export default class Moderator extends Listenable {
478 489
      * @param error - the error result of the request that {@link sendConferenceRequest} sent
479 490
      * @param {Function} callback - the function to be called back upon the
480 491
      * successful allocation of the conference focus
492
+     * @param errorCallback
481 493
      */
482
-    _handleIqError(roomJid, error, callback) {
494
+    _handleIqError(roomJid, error, callback, errorCallback) {
483 495
         // The reservation system only works over XMPP. Handle the error separately.
484 496
         // Check for error returned by the reservation system
485 497
         const reservationErr = $(error).find('>error>reservation-error');
@@ -498,6 +510,8 @@ export default class Moderator extends Listenable {
498 510
                 errorCode,
499 511
                 errorMsg);
500 512
 
513
+            errorCallback();
514
+
501 515
             return;
502 516
         }
503 517
 
@@ -507,7 +521,7 @@ export default class Moderator extends Listenable {
507 521
         // Not authorized to create new room
508 522
         const notAuthorized = $(error).find('>error>not-authorized').length > 0;
509 523
 
510
-        this._handleError(roomJid, invalidSession, notAuthorized, callback);
524
+        this._handleError(roomJid, invalidSession, notAuthorized, callback, errorCallback);
511 525
     }
512 526
 
513 527
     /**
@@ -518,12 +532,13 @@ export default class Moderator extends Listenable {
518 532
      * @param result - the success (i.e. non-error) result of the request that {@link #sendConferenecRequest} sent
519 533
      * @param {Function} callback - the function to be called back upon the
520 534
      * successful allocation of the conference focus
535
+     * @param errorCallback
521 536
      */
522
-    _handleIqSuccess(roomJid, result, callback) {
537
+    _handleIqSuccess(roomJid, result, callback, errorCallback) {
523 538
         // Setup config options
524 539
         const conferenceRequest = this._parseConferenceIq(result);
525 540
 
526
-        this._handleSuccess(roomJid, conferenceRequest, callback);
541
+        this._handleSuccess(roomJid, conferenceRequest, callback, errorCallback);
527 542
     }
528 543
 
529 544
     /**

Loading…
取消
儲存