fix(hangup): Show Feedback independently from room.leave

This commit is contained in:
hristoterezov 2016-10-12 16:30:44 -05:00
parent 58b4e0d59a
commit 71d767f0b4
1 changed files with 26 additions and 59 deletions

View File

@ -38,13 +38,6 @@ let connectionIsInterrupted = false;
*/ */
let DSExternalInstallationInProgress = false; let DSExternalInstallationInProgress = false;
/**
* Listens whether conference had been left from local user when we are trying
* to navigate away from current page.
* @type {HangupConferenceLeftListener}
*/
let conferenceLeftListener = null;
import {VIDEO_CONTAINER_TYPE} from "./modules/UI/videolayout/VideoContainer"; import {VIDEO_CONTAINER_TYPE} from "./modules/UI/videolayout/VideoContainer";
/** /**
@ -219,50 +212,6 @@ function maybeRedirectToWelcomePage(showThankYou) {
}, 3000); }, 3000);
} }
/**
* Listens for CONFERENCE_LEFT event after hangup function has been executed.
*/
class HangupConferenceLeftListener {
/**
* 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(requestFeedback) {
this.requestFeedback = requestFeedback;
room.on(ConferenceEvents.CONFERENCE_LEFT,
this._handleConferenceLeft.bind(this));
}
/**
* Handles the conference left event.
* @private
*/
_handleConferenceLeft() {
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();
}
}
/** /**
* Create local tracks of specified types. * Create local tracks of specified types.
* @param {Object} options * @param {Object} options
@ -486,6 +435,17 @@ function sendTokenDataStats() {
} }
} }
/**
* Disconnects the connection.
* @returns resolved Promise. We need this in order to make the Promise.all
* call in hangup() to resolve when all operations are finished.
*/
function disconnect() {
connection.disconnect();
APP.API.notifyConferenceLeft(APP.conference.roomName);
return Promise.resolve();
}
/** /**
* Set permanent ptoperties to analytics. * Set permanent ptoperties to analytics.
* NOTE: Has to be used after JitsiMeetJS.init. otherwise analytics will be * NOTE: Has to be used after JitsiMeetJS.init. otherwise analytics will be
@ -1784,13 +1744,20 @@ export default {
* requested * requested
*/ */
hangup (requestFeedback = false) { hangup (requestFeedback = false) {
if (!conferenceLeftListener) { APP.UI.hideRingOverLay();
conferenceLeftListener let requestFeedbackPromise = requestFeedback
= new HangupConferenceLeftListener(requestFeedback); ? APP.UI.requestFeedback().catch(() => Promise.resolve())
} : Promise.resolve();
// All promises are returning Promise.resolve to make Promise.all to
//FIXME: Do something for the use case when we are not receiving // be resolved when both Promises are finished. Otherwise Promise.all
// CONFERENCE_LEFT for some reason // will reject on first rejected Promise and we can redirect the page
room.leave(); // before all operations are done.
Promise.all([
requestFeedbackPromise,
room.leave().then(disconnect, disconnect)
]).then(() => {
APP.API.notifyReadyToClose();
maybeRedirectToWelcomePage();
});
} }
}; };