2015-12-09 17:10:49 +00:00
|
|
|
/* global APP, JitsiMeetJS */
|
2016-01-06 22:39:13 +00:00
|
|
|
import UIUtil from '../util/UIUtil';
|
|
|
|
//FIXME:
|
|
|
|
import AnalyticsAdapter from '../../statistics/AnalyticsAdapter';
|
2015-12-09 17:10:49 +00:00
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Show dialog which asks user for new password for the conference.
|
|
|
|
* @returns {Promise<string>} password or nothing if user canceled
|
|
|
|
*/
|
2015-12-09 17:10:49 +00:00
|
|
|
function askForNewPassword () {
|
|
|
|
let passMsg = APP.translation.generateTranslationHTML("dialog.passwordMsg");
|
|
|
|
let yourPassMsg = APP.translation.translateString("dialog.yourPassword");
|
|
|
|
let msg = `
|
|
|
|
<h2>${passMsg}</h2>
|
|
|
|
<input name="lockKey" type="text"
|
|
|
|
data-i18n="[placeholder]dialog.yourPassword"
|
|
|
|
placeholder="${yourPassMsg}" autofocus>
|
|
|
|
`;
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
2016-06-08 19:34:02 +00:00
|
|
|
APP.UI.messageHandler.openTwoButtonDialog(
|
2015-12-09 17:10:49 +00:00
|
|
|
null, null, null,
|
|
|
|
msg, false, "dialog.Save",
|
|
|
|
function (e, v, m, f) {
|
|
|
|
if (v && f.lockKey) {
|
|
|
|
resolve(UIUtil.escapeHtml(f.lockKey));
|
2016-05-23 21:46:41 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-06-08 19:34:02 +00:00
|
|
|
reject(APP.UI.messageHandler.CANCEL);
|
2015-12-09 17:10:49 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
null, null, 'input:first'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Show dialog which asks for required conference password.
|
|
|
|
* @returns {Promise<string>} password or nothing if user canceled
|
|
|
|
*/
|
2015-12-09 17:10:49 +00:00
|
|
|
function askForPassword () {
|
|
|
|
let passRequiredMsg = APP.translation.translateString(
|
|
|
|
"dialog.passwordRequired"
|
|
|
|
);
|
|
|
|
let passMsg = APP.translation.translateString("dialog.password");
|
|
|
|
let msg = `
|
|
|
|
<h2 data-i18n="dialog.passwordRequired">${passRequiredMsg}</h2>
|
|
|
|
<input name="lockKey" type="text"
|
|
|
|
data-i18n="[placeholder]dialog.password"
|
|
|
|
placeholder="${passMsg}" autofocus>
|
|
|
|
`;
|
|
|
|
return new Promise(function (resolve, reject) {
|
2016-06-08 19:34:02 +00:00
|
|
|
APP.UI.messageHandler.openTwoButtonDialog(
|
2015-12-09 17:10:49 +00:00
|
|
|
null, null, null, msg,
|
|
|
|
true, "dialog.Ok",
|
|
|
|
function (e, v, m, f) {}, null,
|
|
|
|
function (e, v, m, f) {
|
|
|
|
if (v && f.lockKey) {
|
|
|
|
resolve(UIUtil.escapeHtml(f.lockKey));
|
|
|
|
} else {
|
2016-06-08 19:34:02 +00:00
|
|
|
reject(APP.UI.messageHandler.CANCEL);
|
2015-12-09 17:10:49 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
':input:first'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Show dialog which asks if user want remove password from the conference.
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
2015-12-09 17:10:49 +00:00
|
|
|
function askToUnlock () {
|
|
|
|
return new Promise(function (resolve, reject) {
|
2016-06-08 19:34:02 +00:00
|
|
|
APP.UI.messageHandler.openTwoButtonDialog(
|
2015-12-09 17:10:49 +00:00
|
|
|
null, null, "dialog.passwordCheck",
|
|
|
|
null, false, "dialog.Remove",
|
|
|
|
function (e, v) {
|
|
|
|
if (v) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
2016-06-08 19:34:02 +00:00
|
|
|
reject(APP.UI.messageHandler.CANCEL);
|
2015-12-09 17:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Show notification that user cannot set password for the conference
|
|
|
|
* because server doesn't support that.
|
|
|
|
*/
|
|
|
|
function notifyPasswordNotSupported () {
|
|
|
|
console.warn('room passwords not supported');
|
2016-06-08 19:34:02 +00:00
|
|
|
APP.UI.messageHandler.showError(
|
|
|
|
"dialog.warning", "dialog.passwordNotSupported");
|
2015-12-09 17:10:49 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Show notification that setting password for the conference failed.
|
|
|
|
* @param {Error} err error
|
|
|
|
*/
|
|
|
|
function notifyPasswordFailed(err) {
|
|
|
|
console.warn('setting password failed', err);
|
2016-06-08 19:34:02 +00:00
|
|
|
APP.UI.messageHandler.showError(
|
|
|
|
"dialog.lockTitle", "dialog.lockMessage");
|
2015-12-09 17:10:49 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 11:57:18 +00:00
|
|
|
const ConferenceErrors = JitsiMeetJS.errors.conference;
|
2015-12-09 17:10:49 +00:00
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Create new RoomLocker for the conference.
|
|
|
|
* It allows to set or remove password for the conference,
|
|
|
|
* or ask for required password.
|
|
|
|
* @returns {RoomLocker}
|
|
|
|
*/
|
2015-12-09 17:10:49 +00:00
|
|
|
export default function createRoomLocker (room) {
|
|
|
|
let password;
|
2016-07-15 20:40:18 +00:00
|
|
|
let dialog = null;
|
2015-12-09 17:10:49 +00:00
|
|
|
|
|
|
|
function lock (newPass) {
|
|
|
|
return room.lock(newPass).then(function () {
|
|
|
|
password = newPass;
|
|
|
|
}).catch(function (err) {
|
2015-12-29 14:41:24 +00:00
|
|
|
console.error(err);
|
2015-12-10 11:57:18 +00:00
|
|
|
if (err === ConferenceErrors.PASSWORD_NOT_SUPPORTED) {
|
2015-12-09 17:10:49 +00:00
|
|
|
notifyPasswordNotSupported();
|
|
|
|
} else {
|
|
|
|
notifyPasswordFailed(err);
|
|
|
|
}
|
|
|
|
throw err;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* @class RoomLocker
|
|
|
|
*/
|
2015-12-09 17:10:49 +00:00
|
|
|
return {
|
|
|
|
get isLocked () {
|
|
|
|
return !!password;
|
|
|
|
},
|
|
|
|
|
|
|
|
get password () {
|
|
|
|
return password;
|
|
|
|
},
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Allows to remove password from the conference (asks user first).
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
2015-12-09 17:10:49 +00:00
|
|
|
askToUnlock () {
|
2016-05-23 21:46:41 +00:00
|
|
|
return askToUnlock().then(
|
|
|
|
() => { return lock(); }
|
|
|
|
).then(function () {
|
2015-12-09 17:10:49 +00:00
|
|
|
AnalyticsAdapter.sendEvent('toolbar.lock.disabled');
|
2016-05-23 21:46:41 +00:00
|
|
|
}).catch(
|
|
|
|
reason => {
|
2016-06-08 19:34:02 +00:00
|
|
|
if (reason !== APP.UI.messageHandler.CANCEL)
|
2016-05-23 21:46:41 +00:00
|
|
|
console.error(reason);
|
|
|
|
}
|
|
|
|
);
|
2015-12-09 17:10:49 +00:00
|
|
|
},
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Allows to set password for the conference.
|
|
|
|
* It asks user for new password and locks the room.
|
|
|
|
* @returns {Promise}
|
|
|
|
*/
|
2015-12-09 17:10:49 +00:00
|
|
|
askToLock () {
|
2016-05-23 21:46:41 +00:00
|
|
|
return askForNewPassword().then(
|
|
|
|
newPass => { return lock(newPass);}
|
|
|
|
).then(function () {
|
2015-12-09 17:10:49 +00:00
|
|
|
AnalyticsAdapter.sendEvent('toolbar.lock.enabled');
|
2016-05-23 21:46:41 +00:00
|
|
|
}).catch(
|
|
|
|
reason => {
|
2016-06-08 19:34:02 +00:00
|
|
|
if (reason !== APP.UI.messageHandler.CANCEL)
|
2016-05-23 21:46:41 +00:00
|
|
|
console.error(reason);
|
|
|
|
}
|
|
|
|
);
|
2015-12-09 17:10:49 +00:00
|
|
|
},
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Asks user for required conference password.
|
|
|
|
*/
|
2015-12-09 17:10:49 +00:00
|
|
|
requirePassword () {
|
2016-05-23 21:46:41 +00:00
|
|
|
return askForPassword().then(
|
|
|
|
newPass => { password = newPass; }
|
|
|
|
).catch(
|
|
|
|
reason => {
|
2016-06-08 19:34:02 +00:00
|
|
|
if (reason !== APP.UI.messageHandler.CANCEL)
|
2016-05-23 21:46:41 +00:00
|
|
|
console.error(reason);
|
|
|
|
}
|
|
|
|
);
|
2015-12-09 17:10:49 +00:00
|
|
|
},
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Show notification that to set/remove password user must be moderator.
|
|
|
|
*/
|
2015-12-09 17:10:49 +00:00
|
|
|
notifyModeratorRequired () {
|
2016-07-15 20:40:18 +00:00
|
|
|
if (dialog)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let closeCallback = function () {
|
|
|
|
dialog = null;
|
|
|
|
};
|
|
|
|
|
2015-12-09 17:10:49 +00:00
|
|
|
if (password) {
|
2016-07-15 20:40:18 +00:00
|
|
|
dialog = APP.UI.messageHandler
|
|
|
|
.openMessageDialog(null, "dialog.passwordError",
|
|
|
|
null, null, closeCallback);
|
2015-12-09 17:10:49 +00:00
|
|
|
} else {
|
2016-07-15 20:40:18 +00:00
|
|
|
dialog = APP.UI.messageHandler
|
|
|
|
.openMessageDialog(null, "dialog.passwordError2",
|
|
|
|
null, null, closeCallback);
|
2015-12-09 17:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|