Skip to content

Commit 83ba892

Browse files
committed
feat(moderator): Make sure we resolve the sendConference promise.
1 parent 604acf0 commit 83ba892

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-18
lines changed

JitsiConnection.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getLogger } from '@jitsi/logger';
2+
13
import JitsiConference from './JitsiConference';
24
import * as JitsiConnectionEvents from './JitsiConnectionEvents';
35
import FeatureFlags from './modules/flags/FeatureFlags';
@@ -8,6 +10,8 @@ import {
810
createConnectionFailedEvent
911
} from './service/statistics/AnalyticsEvents';
1012

13+
const logger = getLogger(__filename);
14+
1115
/**
1216
* Creates a new connection object for the Jitsi Meet server side video
1317
* conferencing service. Provides access to the JitsiConference interface.
@@ -67,7 +71,8 @@ JitsiConnection.prototype.connect = function(options = {}) {
6771
this.xmpp.moderator.sendConferenceRequest(this.xmpp.getRoomJid(options.name))
6872
.then(() => {
6973
this.xmpp.connect(options.id, options.password);
70-
});
74+
})
75+
.catch(e => logger.trace('sendConferenceRequest rejected', e));
7176
} else {
7277
this.xmpp.connect(options.id, options.password);
7378
}

authenticateAndUpgradeRole.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import { getLogger } from '@jitsi/logger';
2+
13
import {
24
CONNECTION_DISCONNECTED,
35
CONNECTION_ESTABLISHED,
46
CONNECTION_FAILED
57
} from './JitsiConnectionEvents';
68
import XMPP from './modules/xmpp/xmpp';
79

10+
const logger = getLogger(__filename);
11+
812
/**
913
* @typedef {Object} UpgradeRoleError
1014
*
@@ -111,7 +115,9 @@ export default function authenticateAndUpgradeRole({
111115
// we execute this logic in JitsiConference where we bind the current conference as `this`
112116
// At this point we should have the new session ID
113117
// 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);
115121
})
116122
.catch(({ error, message }) => {
117123
xmpp.disconnect();

modules/xmpp/ChatRoom.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ export default class ChatRoom extends Listenable {
249249
this.onConnStatusChanged.bind(this))
250250
);
251251
resolve();
252-
});
252+
})
253+
.catch(e => logger.trace('PreJoin rejected', e));
253254
});
254255
}
255256

modules/xmpp/moderator.js

+30-15
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,14 @@ export default class Moderator extends Listenable {
304304
// to mark whether we have already sent a conference request
305305
this.conferenceRequestSent = false;
306306

307-
return new Promise(resolve => {
307+
return new Promise((resolve, reject) => {
308308
if (this.mode === 'xmpp') {
309309
logger.info(`Sending conference request over XMPP to ${this.targetJid}`);
310310

311311
this.connection.sendIQ(
312312
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));
315315

316316
// XXX We're pressed for time here because we're beginning a complex
317317
// and/or lengthy conference-establishment process which supposedly
@@ -335,24 +335,24 @@ export default class Moderator extends Listenable {
335335
&& text.indexOf('400 invalid-session') > 0;
336336
const notAuthorized = response.status === 403;
337337

338-
this._handleError(roomJid, sessionError, notAuthorized, resolve);
338+
this._handleError(roomJid, sessionError, notAuthorized, resolve, reject);
339339
})
340340
.catch(error => {
341341
logger.warn(`Error: ${error}`);
342-
this._handleError(roomJid);
342+
this._handleError(roomJid, undefined, undefined, resolve, reject);
343343
});
344344

345345
// _handleError has either scheduled a retry or fired an event indicating failure.
346346
return;
347347
}
348348
response.json()
349349
.then(resultJson => {
350-
this._handleSuccess(roomJid, resultJson, resolve);
350+
this._handleSuccess(roomJid, resultJson, resolve, reject);
351351
});
352352
})
353353
.catch(error => {
354354
logger.warn(`Error: ${error}`);
355-
this._handleError(roomJid);
355+
this._handleError(roomJid, undefined, undefined, resolve, reject);
356356
});
357357
}
358358
}).then(() => {
@@ -365,9 +365,10 @@ export default class Moderator extends Listenable {
365365
* @param roomJid
366366
* @param conferenceRequest
367367
* @param callback
368+
* @param errorCallback
368369
* @private
369370
*/
370-
_handleSuccess(roomJid, conferenceRequest, callback) {
371+
_handleSuccess(roomJid, conferenceRequest, callback, errorCallback) {
371372
// Reset the error timeout (because we haven't failed here).
372373
this.getNextErrorTimeout(true);
373374

@@ -400,6 +401,8 @@ export default class Moderator extends Listenable {
400401

401402
this.xmpp.eventEmitter.emit(CONNECTION_FAILED, NOT_LIVE_ERROR);
402403

404+
errorCallback();
405+
403406
return;
404407
}
405408

@@ -413,6 +416,8 @@ export default class Moderator extends Listenable {
413416

414417
this.xmpp.eventEmitter.emit(CONNECTION_REDIRECTED, conferenceRequest.vnode, conferenceRequest.focusJid);
415418

419+
errorCallback();
420+
416421
return;
417422
}
418423

@@ -425,7 +430,7 @@ export default class Moderator extends Listenable {
425430
logger.info(`Not ready yet, will retry in ${waitMs} ms.`);
426431
window.setTimeout(
427432
() => this.sendConferenceRequest(roomJid)
428-
.then(callback),
433+
.then(callback).catch(errorCallback),
429434
waitMs);
430435
}
431436
}
@@ -436,9 +441,10 @@ export default class Moderator extends Listenable {
436441
* @param sessionError
437442
* @param notAuthorized
438443
* @param callback
444+
* @param errorCallback
439445
* @private
440446
*/
441-
_handleError(roomJid, sessionError, notAuthorized, callback) {
447+
_handleError(roomJid, sessionError, notAuthorized, callback, errorCallback) { // eslint-disable-line max-params
442448
// If the session is invalid, remove and try again without session ID to get
443449
// a new one
444450
if (sessionError) {
@@ -451,6 +457,8 @@ export default class Moderator extends Listenable {
451457
logger.warn('Unauthorized to start the conference');
452458
this.eventEmitter.emit(XMPPEvents.AUTHENTICATION_REQUIRED);
453459

460+
errorCallback();
461+
454462
return;
455463
}
456464

@@ -461,13 +469,16 @@ export default class Moderator extends Listenable {
461469
logger.info(`Invalid session, will retry after ${waitMs} ms.`);
462470
this.getNextTimeout(true);
463471
window.setTimeout(() => this.sendConferenceRequest(roomJid)
464-
.then(callback), waitMs);
472+
.then(callback)
473+
.catch(errorCallback), waitMs);
465474
} else {
466475
logger.error('Failed to get a successful response, giving up.');
467476

468477
// This is a "fatal" error and the user of the lib should handle it accordingly.
469478
// TODO: change the event name to something accurate.
470479
this.eventEmitter.emit(XMPPEvents.FOCUS_DISCONNECTED);
480+
481+
errorCallback();
471482
}
472483
}
473484

@@ -478,8 +489,9 @@ export default class Moderator extends Listenable {
478489
* @param error - the error result of the request that {@link sendConferenceRequest} sent
479490
* @param {Function} callback - the function to be called back upon the
480491
* successful allocation of the conference focus
492+
* @param errorCallback
481493
*/
482-
_handleIqError(roomJid, error, callback) {
494+
_handleIqError(roomJid, error, callback, errorCallback) {
483495
// The reservation system only works over XMPP. Handle the error separately.
484496
// Check for error returned by the reservation system
485497
const reservationErr = $(error).find('>error>reservation-error');
@@ -498,6 +510,8 @@ export default class Moderator extends Listenable {
498510
errorCode,
499511
errorMsg);
500512

513+
errorCallback();
514+
501515
return;
502516
}
503517

@@ -507,7 +521,7 @@ export default class Moderator extends Listenable {
507521
// Not authorized to create new room
508522
const notAuthorized = $(error).find('>error>not-authorized').length > 0;
509523

510-
this._handleError(roomJid, invalidSession, notAuthorized, callback);
524+
this._handleError(roomJid, invalidSession, notAuthorized, callback, errorCallback);
511525
}
512526

513527
/**
@@ -518,12 +532,13 @@ export default class Moderator extends Listenable {
518532
* @param result - the success (i.e. non-error) result of the request that {@link #sendConferenecRequest} sent
519533
* @param {Function} callback - the function to be called back upon the
520534
* successful allocation of the conference focus
535+
* @param errorCallback
521536
*/
522-
_handleIqSuccess(roomJid, result, callback) {
537+
_handleIqSuccess(roomJid, result, callback, errorCallback) {
523538
// Setup config options
524539
const conferenceRequest = this._parseConferenceIq(result);
525540

526-
this._handleSuccess(roomJid, conferenceRequest, callback);
541+
this._handleSuccess(roomJid, conferenceRequest, callback, errorCallback);
527542
}
528543

529544
/**

0 commit comments

Comments
 (0)