From d793cdc797ce96ae140dc544d86d97412e36799b Mon Sep 17 00:00:00 2001 From: damencho Date: Wed, 28 Sep 2016 16:05:51 -0500 Subject: [PATCH 1/2] Waits for conference left event before navigating away from the page. --- conference.js | 78 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/conference.js b/conference.js index 075e0d1d1..3dc45c35a 100644 --- a/conference.js +++ b/conference.js @@ -39,6 +39,13 @@ let connectionIsInterrupted = false; */ let DSExternalInstallationInProgress = false; +/** + * Listens whether conference had been left from local user when we are trying + * to navigate away from current page. + * @type {ConferenceLeftListener} + */ +let conferenceLeftListener = null; + import {VIDEO_CONTAINER_TYPE} from "./modules/UI/videolayout/VideoContainer"; /** @@ -255,7 +262,7 @@ function disconnectAndShowFeedback(requestFeedback) { * @param {boolean} [requestFeedback=false] if user feedback should be requested */ function hangup (requestFeedback = false) { - const errCallback = (f, err) => { + 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 @@ -270,14 +277,69 @@ function hangup (requestFeedback = false) { } }; const disconnect = disconnectAndShowFeedback.bind(null, requestFeedback); - APP.conference._room.leave() - .then(disconnect) - .catch(errCallback.bind(null, disconnect)) - .then(maybeRedirectToWelcomePage) - .catch(function(err){ - console.log(err); - }); + if (!conferenceLeftListener) + conferenceLeftListener = new ConferenceLeftListener(); + + // Make sure that leave is resolved successfully and the set the handlers + // to be invoked once conference had been left + APP.conference._room.leave() + .then(conferenceLeftListener.setHandler(disconnect, errCallback)) + .catch(errCallback); +} + +/** + * 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. + */ +class ConferenceLeftListener { + /** + * Creates ConferenceLeftListener and start listening for conference + * failed event. + */ + constructor() { + room.on(ConferenceEvents.CONFERENCE_LEFT, + this._handleConferenceLeft.bind(this)); + } + + /** + * Handles the conference left event, if we have a handler we invoke it. + * @private + */ + _handleConferenceLeft() { + this.conferenceLeft = true; + + if (this.handler) + this._handleLeave(); + } + + /** + * Sets the handlers. If we already left the conference invoke them. + * @param handler + * @param errCallback + */ + setHandler (handler, errCallback) { + this.handler = handler; + this.errCallback = errCallback; + + if (this.conferenceLeft) + this._handleLeave(); + } + + /** + * Invokes the handlers. + * @private + */ + _handleLeave() + { + this.handler() + .catch(this.errCallback) + .then(maybeRedirectToWelcomePage) + .catch(function(err){ + console.log(err); + }); + } } /** From 07f111abbdc28907fc8d6ea4a1402c38b42b2e7b Mon Sep 17 00:00:00 2001 From: damencho Date: Wed, 28 Sep 2016 17:27:55 -0500 Subject: [PATCH 2/2] Fixes hangup when callstats is disabled. --- modules/UI/UI.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/UI/UI.js b/modules/UI/UI.js index 773f95fb8..1eec27d2f 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -1102,7 +1102,7 @@ UI.requestFeedback = function () { if (Feedback.isVisible()) return Promise.reject(UIErrors.FEEDBACK_REQUEST_IN_PROGRESS); // Feedback has been submitted already. - else if (Feedback.isSubmitted()) + else if (Feedback.isEnabled() && Feedback.isSubmitted()) return Promise.resolve(); else return new Promise(function (resolve, reject) {