From 83ba892106ddceea24fbaacb9e2d97e47cd062fb Mon Sep 17 00:00:00 2001 From: damencho Date: Fri, 20 Sep 2024 13:32:10 -0500 Subject: [PATCH] feat(moderator): Make sure we resolve the sendConference promise. --- JitsiConnection.js | 7 +++++- authenticateAndUpgradeRole.js | 8 ++++++- modules/xmpp/ChatRoom.js | 3 ++- modules/xmpp/moderator.js | 45 +++++++++++++++++++++++------------ 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/JitsiConnection.js b/JitsiConnection.js index 879a2c98a5..b0d6dbefb5 100644 --- a/JitsiConnection.js +++ b/JitsiConnection.js @@ -1,3 +1,5 @@ +import { getLogger } from '@jitsi/logger'; + import JitsiConference from './JitsiConference'; import * as JitsiConnectionEvents from './JitsiConnectionEvents'; import FeatureFlags from './modules/flags/FeatureFlags'; @@ -8,6 +10,8 @@ import { createConnectionFailedEvent } from './service/statistics/AnalyticsEvents'; +const logger = getLogger(__filename); + /** * Creates a new connection object for the Jitsi Meet server side video * conferencing service. Provides access to the JitsiConference interface. @@ -67,7 +71,8 @@ JitsiConnection.prototype.connect = function(options = {}) { this.xmpp.moderator.sendConferenceRequest(this.xmpp.getRoomJid(options.name)) .then(() => { this.xmpp.connect(options.id, options.password); - }); + }) + .catch(e => logger.trace('sendConferenceRequest rejected', e)); } else { this.xmpp.connect(options.id, options.password); } diff --git a/authenticateAndUpgradeRole.js b/authenticateAndUpgradeRole.js index 18b26b144d..037bb10346 100644 --- a/authenticateAndUpgradeRole.js +++ b/authenticateAndUpgradeRole.js @@ -1,3 +1,5 @@ +import { getLogger } from '@jitsi/logger'; + import { CONNECTION_DISCONNECTED, CONNECTION_ESTABLISHED, @@ -5,6 +7,8 @@ import { } from './JitsiConnectionEvents'; import XMPP from './modules/xmpp/xmpp'; +const logger = getLogger(__filename); + /** * @typedef {Object} UpgradeRoleError * @@ -111,7 +115,9 @@ export default function authenticateAndUpgradeRole({ // we execute this logic in JitsiConference where we bind the current conference as `this` // At this point we should have the new session ID // stored in the settings. Send a new conference IQ. - this.room.xmpp.moderator.sendConferenceRequest(this.room.roomjid).finally(resolve); + this.room.xmpp.moderator.sendConferenceRequest(this.room.roomjid) + .catch(e => logger.trace('sendConferenceRequest rejected', e)) + .finally(resolve); }) .catch(({ error, message }) => { xmpp.disconnect(); diff --git a/modules/xmpp/ChatRoom.js b/modules/xmpp/ChatRoom.js index be8306cca9..7cf8ba4b0f 100644 --- a/modules/xmpp/ChatRoom.js +++ b/modules/xmpp/ChatRoom.js @@ -249,7 +249,8 @@ export default class ChatRoom extends Listenable { this.onConnStatusChanged.bind(this)) ); resolve(); - }); + }) + .catch(e => logger.trace('PreJoin rejected', e)); }); } diff --git a/modules/xmpp/moderator.js b/modules/xmpp/moderator.js index 83c27c9116..64310cee27 100644 --- a/modules/xmpp/moderator.js +++ b/modules/xmpp/moderator.js @@ -304,14 +304,14 @@ export default class Moderator extends Listenable { // to mark whether we have already sent a conference request this.conferenceRequestSent = false; - return new Promise(resolve => { + return new Promise((resolve, reject) => { if (this.mode === 'xmpp') { logger.info(`Sending conference request over XMPP to ${this.targetJid}`); this.connection.sendIQ( this._createConferenceIq(roomJid), - result => this._handleIqSuccess(roomJid, result, resolve), - error => this._handleIqError(roomJid, error, resolve)); + result => this._handleIqSuccess(roomJid, result, resolve, reject), + error => this._handleIqError(roomJid, error, resolve, reject)); // XXX We're pressed for time here because we're beginning a complex // and/or lengthy conference-establishment process which supposedly @@ -335,11 +335,11 @@ export default class Moderator extends Listenable { && text.indexOf('400 invalid-session') > 0; const notAuthorized = response.status === 403; - this._handleError(roomJid, sessionError, notAuthorized, resolve); + this._handleError(roomJid, sessionError, notAuthorized, resolve, reject); }) .catch(error => { logger.warn(`Error: ${error}`); - this._handleError(roomJid); + this._handleError(roomJid, undefined, undefined, resolve, reject); }); // _handleError has either scheduled a retry or fired an event indicating failure. @@ -347,12 +347,12 @@ export default class Moderator extends Listenable { } response.json() .then(resultJson => { - this._handleSuccess(roomJid, resultJson, resolve); + this._handleSuccess(roomJid, resultJson, resolve, reject); }); }) .catch(error => { logger.warn(`Error: ${error}`); - this._handleError(roomJid); + this._handleError(roomJid, undefined, undefined, resolve, reject); }); } }).then(() => { @@ -365,9 +365,10 @@ export default class Moderator extends Listenable { * @param roomJid * @param conferenceRequest * @param callback + * @param errorCallback * @private */ - _handleSuccess(roomJid, conferenceRequest, callback) { + _handleSuccess(roomJid, conferenceRequest, callback, errorCallback) { // Reset the error timeout (because we haven't failed here). this.getNextErrorTimeout(true); @@ -400,6 +401,8 @@ export default class Moderator extends Listenable { this.xmpp.eventEmitter.emit(CONNECTION_FAILED, NOT_LIVE_ERROR); + errorCallback(); + return; } @@ -413,6 +416,8 @@ export default class Moderator extends Listenable { this.xmpp.eventEmitter.emit(CONNECTION_REDIRECTED, conferenceRequest.vnode, conferenceRequest.focusJid); + errorCallback(); + return; } @@ -425,7 +430,7 @@ export default class Moderator extends Listenable { logger.info(`Not ready yet, will retry in ${waitMs} ms.`); window.setTimeout( () => this.sendConferenceRequest(roomJid) - .then(callback), + .then(callback).catch(errorCallback), waitMs); } } @@ -436,9 +441,10 @@ export default class Moderator extends Listenable { * @param sessionError * @param notAuthorized * @param callback + * @param errorCallback * @private */ - _handleError(roomJid, sessionError, notAuthorized, callback) { + _handleError(roomJid, sessionError, notAuthorized, callback, errorCallback) { // eslint-disable-line max-params // If the session is invalid, remove and try again without session ID to get // a new one if (sessionError) { @@ -451,6 +457,8 @@ export default class Moderator extends Listenable { logger.warn('Unauthorized to start the conference'); this.eventEmitter.emit(XMPPEvents.AUTHENTICATION_REQUIRED); + errorCallback(); + return; } @@ -461,13 +469,16 @@ export default class Moderator extends Listenable { logger.info(`Invalid session, will retry after ${waitMs} ms.`); this.getNextTimeout(true); window.setTimeout(() => this.sendConferenceRequest(roomJid) - .then(callback), waitMs); + .then(callback) + .catch(errorCallback), waitMs); } else { logger.error('Failed to get a successful response, giving up.'); // This is a "fatal" error and the user of the lib should handle it accordingly. // TODO: change the event name to something accurate. this.eventEmitter.emit(XMPPEvents.FOCUS_DISCONNECTED); + + errorCallback(); } } @@ -478,8 +489,9 @@ export default class Moderator extends Listenable { * @param error - the error result of the request that {@link sendConferenceRequest} sent * @param {Function} callback - the function to be called back upon the * successful allocation of the conference focus + * @param errorCallback */ - _handleIqError(roomJid, error, callback) { + _handleIqError(roomJid, error, callback, errorCallback) { // The reservation system only works over XMPP. Handle the error separately. // Check for error returned by the reservation system const reservationErr = $(error).find('>error>reservation-error'); @@ -498,6 +510,8 @@ export default class Moderator extends Listenable { errorCode, errorMsg); + errorCallback(); + return; } @@ -507,7 +521,7 @@ export default class Moderator extends Listenable { // Not authorized to create new room const notAuthorized = $(error).find('>error>not-authorized').length > 0; - this._handleError(roomJid, invalidSession, notAuthorized, callback); + this._handleError(roomJid, invalidSession, notAuthorized, callback, errorCallback); } /** @@ -518,12 +532,13 @@ export default class Moderator extends Listenable { * @param result - the success (i.e. non-error) result of the request that {@link #sendConferenecRequest} sent * @param {Function} callback - the function to be called back upon the * successful allocation of the conference focus + * @param errorCallback */ - _handleIqSuccess(roomJid, result, callback) { + _handleIqSuccess(roomJid, result, callback, errorCallback) { // Setup config options const conferenceRequest = this._parseConferenceIq(result); - this._handleSuccess(roomJid, conferenceRequest, callback); + this._handleSuccess(roomJid, conferenceRequest, callback, errorCallback); } /**