Make sure we have only one dialog instance.

This commit is contained in:
damencho 2016-07-06 13:26:27 -05:00
parent d5de49b5cf
commit 5dffddceec
2 changed files with 64 additions and 15 deletions

View File

@ -21,6 +21,10 @@ import Feedback from '../Feedback.js';
import Toolbar from '../toolbars/Toolbar'; import Toolbar from '../toolbars/Toolbar';
import BottomToolbar from '../toolbars/BottomToolbar'; import BottomToolbar from '../toolbars/BottomToolbar';
/**
* The dialog for user input.
*/
let dialog = null;
/** /**
* Indicates if the recording button should be enabled. * Indicates if the recording button should be enabled.
@ -50,7 +54,7 @@ function _requestLiveStreamId() {
"liveStreaming.streamIdRequired"); "liveStreaming.streamIdRequired");
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
let dialog = APP.UI.messageHandler.openDialogWithStates({ dialog = APP.UI.messageHandler.openDialogWithStates({
state0: { state0: {
html: html:
`<h2>${msg}</h2> `<h2>${msg}</h2>
@ -104,6 +108,10 @@ function _requestLiveStreamId() {
} }
} }
} }
}, {
close: function () {
dialog = null;
}
}); });
}); });
} }
@ -117,7 +125,7 @@ function _requestRecordingToken () {
let token = APP.translation.translateString("dialog.token"); let token = APP.translation.translateString("dialog.token");
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
APP.UI.messageHandler.openTwoButtonDialog( dialog = APP.UI.messageHandler.openTwoButtonDialog(
null, null, null, null, null, null,
`<h2>${msg}</h2> `<h2>${msg}</h2>
<input name="recordingToken" type="text" <input name="recordingToken" type="text"
@ -132,7 +140,9 @@ function _requestRecordingToken () {
} }
}, },
null, null,
function () { }, function () {
dialog = null;
},
':input:first' ':input:first'
); );
}); });
@ -161,7 +171,7 @@ function _showStopRecordingPrompt (recordingType) {
} }
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
APP.UI.messageHandler.openTwoButtonDialog( dialog = APP.UI.messageHandler.openTwoButtonDialog(
title, title,
null, null,
message, message,
@ -174,6 +184,10 @@ function _showStopRecordingPrompt (recordingType) {
} else { } else {
reject(); reject();
} }
},
null,
function () {
dialog = null;
} }
); );
}); });
@ -279,11 +293,15 @@ var Recording = {
var self = this; var self = this;
selector.click(function () { selector.click(function () {
if (dialog)
return;
switch (self.currentState) { switch (self.currentState) {
case Status.ON: case Status.ON:
case Status.PENDING: { case Status.PENDING: {
_showStopRecordingPrompt(recordingType).then(() => _showStopRecordingPrompt(recordingType).then(() =>
self.eventEmitter.emit(UIEvents.RECORDING_TOGGLED)); self.eventEmitter.emit(UIEvents.RECORDING_TOGGLED),
() => {});
break; break;
} }
case Status.AVAILABLE: case Status.AVAILABLE:
@ -318,16 +336,24 @@ var Recording = {
break; break;
} }
case Status.BUSY: { case Status.BUSY: {
APP.UI.messageHandler.openMessageDialog( dialog = APP.UI.messageHandler.openMessageDialog(
self.recordingTitle, self.recordingTitle,
self.recordingBusy self.recordingBusy,
null, null,
function () {
dialog = null;
}
); );
break; break;
} }
default: { default: {
APP.UI.messageHandler.openMessageDialog( dialog = APP.UI.messageHandler.openMessageDialog(
self.recordingTitle, self.recordingTitle,
self.recordingUnavailable self.recordingUnavailable,
null, null,
function () {
dialog = null;
}
); );
} }
} }

View File

@ -17,6 +17,13 @@ export const SHARED_VIDEO_CONTAINER_TYPE = "sharedvideo";
*/ */
const defaultSharedVideoLink = "https://www.youtube.com/watch?v=xNXN7CZk8X0"; const defaultSharedVideoLink = "https://www.youtube.com/watch?v=xNXN7CZk8X0";
const updateInterval = 5000; // milliseconds const updateInterval = 5000; // milliseconds
/**
* The dialog for user input (video link).
* @type {null}
*/
let dialog = null;
/** /**
* Manager of shared video. * Manager of shared video.
*/ */
@ -56,11 +63,14 @@ export default class SharedVideoManager {
* asks whether the user wants to stop sharing the video. * asks whether the user wants to stop sharing the video.
*/ */
toggleSharedVideo () { toggleSharedVideo () {
if (dialog)
return;
if(!this.isSharedVideoShown) { if(!this.isSharedVideoShown) {
requestVideoLink().then( requestVideoLink().then(
url => this.emitter.emit( url => this.emitter.emit(
UIEvents.UPDATE_SHARED_VIDEO, url, 'start'), UIEvents.UPDATE_SHARED_VIDEO, url, 'start'),
err => console.error('SHARED VIDEO CANCELED', err) err => console.log('SHARED VIDEO CANCELED', err)
); );
return; return;
} }
@ -68,11 +78,16 @@ export default class SharedVideoManager {
if(APP.conference.isLocalId(this.from)) { if(APP.conference.isLocalId(this.from)) {
showStopVideoPropmpt().then(() => showStopVideoPropmpt().then(() =>
this.emitter.emit( this.emitter.emit(
UIEvents.UPDATE_SHARED_VIDEO, this.url, 'stop')); UIEvents.UPDATE_SHARED_VIDEO, this.url, 'stop'),
() => {});
} else { } else {
APP.UI.messageHandler.openMessageDialog( dialog = APP.UI.messageHandler.openMessageDialog(
"dialog.shareVideoTitle", "dialog.shareVideoTitle",
"dialog.alreadySharedVideoMsg" "dialog.alreadySharedVideoMsg",
null, null,
function () {
dialog = null;
}
); );
} }
} }
@ -700,7 +715,7 @@ function getYoutubeLink(url) {
*/ */
function showStopVideoPropmpt() { function showStopVideoPropmpt() {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
APP.UI.messageHandler.openTwoButtonDialog( dialog = APP.UI.messageHandler.openTwoButtonDialog(
"dialog.removeSharedVideoTitle", "dialog.removeSharedVideoTitle",
null, null,
"dialog.removeSharedVideoMsg", "dialog.removeSharedVideoMsg",
@ -713,6 +728,10 @@ function showStopVideoPropmpt() {
} else { } else {
reject(); reject();
} }
},
null,
function () {
dialog = null;
} }
); );
@ -735,7 +754,7 @@ function requestVideoLink() {
const defaultUrl = i18n.translateString("defaultLink", i18nOptions); const defaultUrl = i18n.translateString("defaultLink", i18nOptions);
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
let dialog = APP.UI.messageHandler.openDialogWithStates({ dialog = APP.UI.messageHandler.openDialogWithStates({
state0: { state0: {
html: ` html: `
<h2>${title}</h2> <h2>${title}</h2>
@ -795,6 +814,10 @@ function requestVideoLink() {
} }
} }
} }
}, {
close: function () {
dialog = null;
}
}); });
}); });