|
|
@@ -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
|
/**
|