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

View File

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

View File

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