From 62f7553ba4361405256c8aed482c87f66d37feca Mon Sep 17 00:00:00 2001 From: damencho Date: Wed, 6 Jul 2016 11:00:04 -0500 Subject: [PATCH 1/4] Updates two button dialogs to be only single instance. --- modules/UI/util/MessageHandler.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/modules/UI/util/MessageHandler.js b/modules/UI/util/MessageHandler.js index 13b55bf81..2324e4b76 100644 --- a/modules/UI/util/MessageHandler.js +++ b/modules/UI/util/MessageHandler.js @@ -15,6 +15,12 @@ let notificationsEnabled = true; */ let popupEnabled = true; +/** + * Currently displayed two button dialog. + * @type {null} + */ +let twoButtonDialog = null; + var messageHandler = { OK: "dialog.OK", CANCEL: "dialog.Cancel", @@ -68,7 +74,7 @@ var messageHandler = { persistent, leftButtonKey, submitFunction, loadedFunction, closeFunction, focus, defaultButton) { - if (!popupEnabled) + if (!popupEnabled || twoButtonDialog) return; var buttons = []; @@ -87,15 +93,23 @@ var messageHandler = { if (msgKey) { message = APP.translation.generateTranslationHTML(msgKey); } - $.prompt(message, { + twoButtonDialog = $.prompt(message, { title: title, persistent: false, buttons: buttons, defaultButton: defaultButton, focus: focus, loaded: loadedFunction, - submit: submitFunction, - close: closeFunction + submit: function (e, v, m, f) { + twoButtonDialog = null; + if (submitFunction) + submitFunction(e, v, m, f); + }, + close: function () { + twoButtonDialog = null; + if (closeFunction) + closeFunction(); + } }); }, @@ -133,7 +147,7 @@ var messageHandler = { if (persistent) { args.closeText = ''; } - + return new Impromptu(msgString, args); }, From d5de49b5cf9e34ef9040c1ebaae4419099037392 Mon Sep 17 00:00:00 2001 From: damencho Date: Wed, 6 Jul 2016 13:10:45 -0500 Subject: [PATCH 2/4] Returns the dialog instances that were created and adds an optional close callback. --- modules/UI/util/MessageHandler.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/UI/util/MessageHandler.js b/modules/UI/util/MessageHandler.js index 2324e4b76..c8935285a 100644 --- a/modules/UI/util/MessageHandler.js +++ b/modules/UI/util/MessageHandler.js @@ -36,10 +36,14 @@ var messageHandler = { * titleKey will be used to get a title via the translation API. * @param message the message to show. If a falsy value is provided, * messageKey will be used to get a message via the translation API. + * @param closeFunction function to be called after + * the prompt is closed (optional) + * @return the prompt that was created, or null */ - openMessageDialog: function(titleKey, messageKey, title, message) { + openMessageDialog: function(titleKey, messageKey, title, message, + closedFunction) { if (!popupEnabled) - return; + return null; if (!title) { title = APP.translation.generateTranslationHTML(titleKey); @@ -48,9 +52,13 @@ var messageHandler = { message = APP.translation.generateTranslationHTML(messageKey); } - $.prompt(message, - {title: title, persistent: false} - ); + return $.prompt(message, { + title: title, + persistent: false, + close: function () { + if(closedFunction) closedFunction(); + } + }); }, /** * Shows a message to the user with two buttons: first is given as a @@ -69,13 +77,14 @@ var messageHandler = { * the dialog is opened * @param defaultButton index of default button which will be activated when * the user press 'enter'. Indexed from 0. + * @return the prompt that was created, or null */ openTwoButtonDialog: function(titleKey, titleString, msgKey, msgString, persistent, leftButtonKey, submitFunction, loadedFunction, closeFunction, focus, defaultButton) { if (!popupEnabled || twoButtonDialog) - return; + return null; var buttons = []; @@ -111,6 +120,7 @@ var messageHandler = { closeFunction(); } }); + return twoButtonDialog; }, /** From 5dffddceec213c638e4b76afc120c766397becfb Mon Sep 17 00:00:00 2001 From: damencho Date: Wed, 6 Jul 2016 13:26:27 -0500 Subject: [PATCH 3/4] Make sure we have only one dialog instance. --- modules/UI/recording/Recording.js | 44 ++++++++++++++++++++------ modules/UI/shared_video/SharedVideo.js | 35 ++++++++++++++++---- 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/modules/UI/recording/Recording.js b/modules/UI/recording/Recording.js index 261687ff4..ecdb58355 100644 --- a/modules/UI/recording/Recording.js +++ b/modules/UI/recording/Recording.js @@ -21,6 +21,10 @@ import Feedback from '../Feedback.js'; import Toolbar from '../toolbars/Toolbar'; import BottomToolbar from '../toolbars/BottomToolbar'; +/** + * The dialog for user input. + */ +let dialog = null; /** * Indicates if the recording button should be enabled. @@ -50,7 +54,7 @@ function _requestLiveStreamId() { "liveStreaming.streamIdRequired"); return new Promise(function (resolve, reject) { - let dialog = APP.UI.messageHandler.openDialogWithStates({ + dialog = APP.UI.messageHandler.openDialogWithStates({ state0: { html: `

${msg}

@@ -104,6 +108,10 @@ function _requestLiveStreamId() { } } } + }, { + close: function () { + dialog = null; + } }); }); } @@ -117,7 +125,7 @@ function _requestRecordingToken () { let token = APP.translation.translateString("dialog.token"); return new Promise(function (resolve, reject) { - APP.UI.messageHandler.openTwoButtonDialog( + dialog = APP.UI.messageHandler.openTwoButtonDialog( null, null, null, `

${msg}

- self.eventEmitter.emit(UIEvents.RECORDING_TOGGLED)); + self.eventEmitter.emit(UIEvents.RECORDING_TOGGLED), + () => {}); break; } case Status.AVAILABLE: @@ -318,16 +336,24 @@ var Recording = { break; } case Status.BUSY: { - APP.UI.messageHandler.openMessageDialog( + dialog = APP.UI.messageHandler.openMessageDialog( self.recordingTitle, - self.recordingBusy + self.recordingBusy, + null, null, + function () { + dialog = null; + } ); break; } default: { - APP.UI.messageHandler.openMessageDialog( + dialog = APP.UI.messageHandler.openMessageDialog( self.recordingTitle, - self.recordingUnavailable + self.recordingUnavailable, + null, null, + function () { + dialog = null; + } ); } } diff --git a/modules/UI/shared_video/SharedVideo.js b/modules/UI/shared_video/SharedVideo.js index 827334718..562e9d981 100644 --- a/modules/UI/shared_video/SharedVideo.js +++ b/modules/UI/shared_video/SharedVideo.js @@ -17,6 +17,13 @@ export const SHARED_VIDEO_CONTAINER_TYPE = "sharedvideo"; */ const defaultSharedVideoLink = "https://www.youtube.com/watch?v=xNXN7CZk8X0"; const updateInterval = 5000; // milliseconds + +/** + * The dialog for user input (video link). + * @type {null} + */ +let dialog = null; + /** * Manager of shared video. */ @@ -56,11 +63,14 @@ export default class SharedVideoManager { * asks whether the user wants to stop sharing the video. */ toggleSharedVideo () { + if (dialog) + return; + if(!this.isSharedVideoShown) { requestVideoLink().then( url => this.emitter.emit( UIEvents.UPDATE_SHARED_VIDEO, url, 'start'), - err => console.error('SHARED VIDEO CANCELED', err) + err => console.log('SHARED VIDEO CANCELED', err) ); return; } @@ -68,11 +78,16 @@ export default class SharedVideoManager { if(APP.conference.isLocalId(this.from)) { showStopVideoPropmpt().then(() => this.emitter.emit( - UIEvents.UPDATE_SHARED_VIDEO, this.url, 'stop')); + UIEvents.UPDATE_SHARED_VIDEO, this.url, 'stop'), + () => {}); } else { - APP.UI.messageHandler.openMessageDialog( + dialog = APP.UI.messageHandler.openMessageDialog( "dialog.shareVideoTitle", - "dialog.alreadySharedVideoMsg" + "dialog.alreadySharedVideoMsg", + null, null, + function () { + dialog = null; + } ); } } @@ -700,7 +715,7 @@ function getYoutubeLink(url) { */ function showStopVideoPropmpt() { return new Promise(function (resolve, reject) { - APP.UI.messageHandler.openTwoButtonDialog( + dialog = APP.UI.messageHandler.openTwoButtonDialog( "dialog.removeSharedVideoTitle", null, "dialog.removeSharedVideoMsg", @@ -713,6 +728,10 @@ function showStopVideoPropmpt() { } else { reject(); } + }, + null, + function () { + dialog = null; } ); @@ -735,7 +754,7 @@ function requestVideoLink() { const defaultUrl = i18n.translateString("defaultLink", i18nOptions); return new Promise(function (resolve, reject) { - let dialog = APP.UI.messageHandler.openDialogWithStates({ + dialog = APP.UI.messageHandler.openDialogWithStates({ state0: { html: `

${title}

@@ -795,6 +814,10 @@ function requestVideoLink() { } } } + }, { + close: function () { + dialog = null; + } }); }); From 615daa8c9fdcb87c59783753a9438b397644b89b Mon Sep 17 00:00:00 2001 From: damencho Date: Wed, 6 Jul 2016 13:52:59 -0500 Subject: [PATCH 4/4] Updates close function parameters. --- modules/UI/util/MessageHandler.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/UI/util/MessageHandler.js b/modules/UI/util/MessageHandler.js index c8935285a..1c336600e 100644 --- a/modules/UI/util/MessageHandler.js +++ b/modules/UI/util/MessageHandler.js @@ -41,7 +41,7 @@ var messageHandler = { * @return the prompt that was created, or null */ openMessageDialog: function(titleKey, messageKey, title, message, - closedFunction) { + closeFunction) { if (!popupEnabled) return null; @@ -55,8 +55,9 @@ var messageHandler = { return $.prompt(message, { title: title, persistent: false, - close: function () { - if(closedFunction) closedFunction(); + close: function (e, v, m, f) { + if(closeFunction) + closeFunction(e, v, m, f); } }); }, @@ -114,10 +115,10 @@ var messageHandler = { if (submitFunction) submitFunction(e, v, m, f); }, - close: function () { + close: function (e, v, m, f) { twoButtonDialog = null; if (closeFunction) - closeFunction(); + closeFunction(e, v, m, f); } }); return twoButtonDialog;