瀏覽代碼

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

+ 7
- 1
authenticateAndUpgradeRole.js 查看文件

1
+import { getLogger } from '@jitsi/logger';
2
+
1
 import {
3
 import {
2
     CONNECTION_DISCONNECTED,
4
     CONNECTION_DISCONNECTED,
3
     CONNECTION_ESTABLISHED,
5
     CONNECTION_ESTABLISHED,
5
 } from './JitsiConnectionEvents';
7
 } from './JitsiConnectionEvents';
6
 import XMPP from './modules/xmpp/xmpp';
8
 import XMPP from './modules/xmpp/xmpp';
7
 
9
 
10
+const logger = getLogger(__filename);
11
+
8
 /**
12
 /**
9
  * @typedef {Object} UpgradeRoleError
13
  * @typedef {Object} UpgradeRoleError
10
  *
14
  *
111
                         // we execute this logic in JitsiConference where we bind the current conference as `this`
115
                         // we execute this logic in JitsiConference where we bind the current conference as `this`
112
                         // At this point we should have the new session ID
116
                         // At this point we should have the new session ID
113
                         // stored in the settings. Send a new conference IQ.
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
                     .catch(({ error, message }) => {
122
                     .catch(({ error, message }) => {
117
                         xmpp.disconnect();
123
                         xmpp.disconnect();

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

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