Handle Promise.reject for user cancel case

This commit is contained in:
yanas 2016-05-23 16:46:41 -05:00
parent 8418fc97f1
commit 0cf291d796
3 changed files with 48 additions and 21 deletions

View File

@ -25,8 +25,9 @@ function askForNewPassword () {
function (e, v, m, f) { function (e, v, m, f) {
if (v && f.lockKey) { if (v && f.lockKey) {
resolve(UIUtil.escapeHtml(f.lockKey)); resolve(UIUtil.escapeHtml(f.lockKey));
} else { }
reject(); else {
reject(messageHandler.CANCEL);
} }
}, },
null, null, 'input:first' null, null, 'input:first'
@ -58,7 +59,7 @@ function askForPassword () {
if (v && f.lockKey) { if (v && f.lockKey) {
resolve(UIUtil.escapeHtml(f.lockKey)); resolve(UIUtil.escapeHtml(f.lockKey));
} else { } else {
reject(); reject(messageHandler.CANCEL);
} }
}, },
':input:first' ':input:first'
@ -79,7 +80,7 @@ function askToUnlock () {
if (v) { if (v) {
resolve(); resolve();
} else { } else {
reject(); reject(messageHandler.CANCEL);
} }
} }
); );
@ -146,11 +147,16 @@ export default function createRoomLocker (room) {
* @returns {Promise} * @returns {Promise}
*/ */
askToUnlock () { askToUnlock () {
return askToUnlock().then(function () { return askToUnlock().then(
return lock(); () => { return lock(); }
}).then(function () { ).then(function () {
AnalyticsAdapter.sendEvent('toolbar.lock.disabled'); AnalyticsAdapter.sendEvent('toolbar.lock.disabled');
}); }).catch(
reason => {
if (reason !== messageHandler.CANCEL)
console.error(reason);
}
);
}, },
/** /**
@ -159,20 +165,30 @@ export default function createRoomLocker (room) {
* @returns {Promise} * @returns {Promise}
*/ */
askToLock () { askToLock () {
return askForNewPassword().then(function (newPass) { return askForNewPassword().then(
return lock(newPass); newPass => { return lock(newPass);}
}).then(function () { ).then(function () {
AnalyticsAdapter.sendEvent('toolbar.lock.enabled'); AnalyticsAdapter.sendEvent('toolbar.lock.enabled');
}); }).catch(
reason => {
if (reason !== messageHandler.CANCEL)
console.error(reason);
}
);
}, },
/** /**
* Asks user for required conference password. * Asks user for required conference password.
*/ */
requirePassword () { requirePassword () {
return askForPassword().then(function (newPass) { return askForPassword().then(
password = newPass; newPass => { password = newPass; }
}); ).catch(
reason => {
if (reason !== messageHandler.CANCEL)
console.error(reason);
}
);
}, },
/** /**

View File

@ -78,7 +78,7 @@ function _requestLiveStreamId() {
return false; return false;
} }
} else { } else {
reject(); reject(APP.UI.messageHandler.CANCEL);
dialog.close(); dialog.close();
return false; return false;
} }
@ -97,7 +97,7 @@ function _requestLiveStreamId() {
submit: function (e, v, m, f) { submit: function (e, v, m, f) {
e.preventDefault(); e.preventDefault();
if (v === 0) { if (v === 0) {
reject(); reject(APP.UI.messageHandler.CANCEL);
dialog.close(); dialog.close();
} else { } else {
dialog.goToState('state0'); dialog.goToState('state0');
@ -128,7 +128,7 @@ function _requestRecordingToken () {
if (v && f.recordingToken) { if (v && f.recordingToken) {
resolve(UIUtil.escapeHtml(f.recordingToken)); resolve(UIUtil.escapeHtml(f.recordingToken));
} else { } else {
reject(); reject(APP.UI.messageHandler.CANCEL);
} }
}, },
null, null,
@ -282,7 +282,12 @@ var Recording = {
_requestLiveStreamId().then((streamId) => { _requestLiveStreamId().then((streamId) => {
self.eventEmitter.emit( UIEvents.RECORDING_TOGGLED, self.eventEmitter.emit( UIEvents.RECORDING_TOGGLED,
{streamId: streamId}); {streamId: streamId});
}); }).catch(
reason => {
if (reason !== APP.UI.messageHandler.CANCEL)
console.error(reason);
}
);
else { else {
if (self.predefinedToken) { if (self.predefinedToken) {
self.eventEmitter.emit( UIEvents.RECORDING_TOGGLED, self.eventEmitter.emit( UIEvents.RECORDING_TOGGLED,
@ -293,7 +298,12 @@ var Recording = {
_requestRecordingToken().then((token) => { _requestRecordingToken().then((token) => {
self.eventEmitter.emit( UIEvents.RECORDING_TOGGLED, self.eventEmitter.emit( UIEvents.RECORDING_TOGGLED,
{token: token}); {token: token});
}); }).catch(
reason => {
if (reason !== APP.UI.messageHandler.CANCEL)
console.error(reason);
}
);
} }
break; break;
} }

View File

@ -10,7 +10,8 @@ import UIUtil from './UIUtil';
var notificationsEnabled = true; var notificationsEnabled = true;
var messageHandler = (function(my) { var messageHandler = (function(my) {
my.OK = "dialog.OK",
my.CANCEL = "dialog.Cancel",
/** /**
* Shows a message to the user. * Shows a message to the user.
* *