diff --git a/conference.js b/conference.js index 72b600b46..11b20cc97 100644 --- a/conference.js +++ b/conference.js @@ -16,7 +16,6 @@ import mediaDeviceHelper from './modules/devices/mediaDeviceHelper'; import {reportError} from './modules/util/helpers'; -import UIErrors from './modules/UI/UIErrors'; import UIUtil from './modules/UI/util/UIUtil'; const ConnectionErrors = JitsiMeetJS.errors.connection; @@ -42,7 +41,7 @@ let DSExternalInstallationInProgress = false; /** * Listens whether conference had been left from local user when we are trying * to navigate away from current page. - * @type {ConferenceLeftListener} + * @type {HangupConferenceLeftListener} */ let conferenceLeftListener = null; @@ -220,50 +219,47 @@ function maybeRedirectToWelcomePage(showThankYou) { }, 3000); } -/** - * Executes connection.disconnect and shows the feedback dialog - * @param {boolean} [requestFeedback=false] if user feedback should be requested - * @returns Promise. - */ -function disconnectAndShowFeedback(requestFeedback) { - APP.UI.hideRingOverLay(); - connection.disconnect(); - APP.API.notifyConferenceLeft(APP.conference.roomName); - let promise = (requestFeedback? - APP.UI.requestFeedback(): Promise.resolve()); - promise.then(() => APP.API.notifyReadyToClose()); - return promise; -} /** - * Listens for CONFERENCE_LEFT event so we can check whether it has finished. - * The handler will be called once the conference had been left or if it - * was already left when we are adding the handler. + * Listens for CONFERENCE_LEFT event after hangup function has been executed. */ -class ConferenceLeftListener { +class HangupConferenceLeftListener { /** - * Creates ConferenceLeftListener and start listening for conference - * failed event. - * @param {Function} handler the function that will be called when - * CONFERENCE_LEFT event is fired. - * @param errCallback + * Creates HangupConferenceLeftListener and start listening for conference + * left event. On CONFERENCE_LEFT event calls should disconnect the user + * and maybe show the feedback dialog. + * @param {boolean} [requestFeedback=false] if user feedback should be + * requested */ - constructor(handler) { - this.handler = handler; + constructor(requestFeedback) { + this.requestFeedback = requestFeedback; room.on(ConferenceEvents.CONFERENCE_LEFT, this._handleConferenceLeft.bind(this)); } /** - * Handles the conference left event, if we have a handler we invoke it. + * Handles the conference left event. * @private */ _handleConferenceLeft() { - this.handler() - .then(maybeRedirectToWelcomePage) - .catch(function(err){ - console.log(err); - }); + this._disconnectAndShowFeedback() + .then(() => { + APP.API.notifyReadyToClose(); + maybeRedirectToWelcomePage(); + }).catch(console.log); + } + + /** + * Executes connection.disconnect and shows the feedback dialog + * @returns Promise. + * @private + */ + _disconnectAndShowFeedback() { + APP.UI.hideRingOverLay(); + connection.disconnect(); + APP.API.notifyConferenceLeft(APP.conference.roomName); + return (this.requestFeedback) ? + APP.UI.requestFeedback() : Promise.resolve(); } } @@ -1780,30 +1776,13 @@ export default { * requested */ hangup (requestFeedback = false) { - const errCallback = (err) => { - // If we want to break out the chain in our error handler, it needs - // to return a rejected promise. In the case of feedback request - // in progress it's important to not redirect to the welcome page - // (see below maybeRedirectToWelcomePage call). - if (err === UIErrors.FEEDBACK_REQUEST_IN_PROGRESS) { - return Promise.reject('Feedback request in progress.'); - } - else { - console.error('Error occurred during hanging up: ', err); - return Promise.resolve(); - } - }; - - const disconnect = () => { - return disconnectAndShowFeedback(requestFeedback) - .catch(errCallback); - }; - if (!conferenceLeftListener) { conferenceLeftListener - = new ConferenceLeftListener(disconnect, errCallback); + = new HangupConferenceLeftListener(requestFeedback); } - room.leave().catch(errCallback); + //FIXME: Do something for the use case when we are not receiving + // CONFERENCE_LEFT for some reason + room.leave(); } };