2017-10-10 23:31:40 +00:00
|
|
|
/* global $, APP, config */
|
2017-09-18 07:09:43 +00:00
|
|
|
|
2020-06-04 14:09:13 +00:00
|
|
|
import { toJid } from '../../../react/features/base/connection/functions';
|
2017-10-10 23:31:40 +00:00
|
|
|
import {
|
|
|
|
JitsiConnectionErrors
|
|
|
|
} from '../../../react/features/base/lib-jitsi-meet';
|
2015-03-13 14:01:42 +00:00
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Build html for "password required" dialog.
|
|
|
|
* @returns {string} html string
|
|
|
|
*/
|
2015-12-17 15:31:11 +00:00
|
|
|
function getPasswordInputHtml() {
|
2017-10-12 23:02:29 +00:00
|
|
|
const placeholder = config.hosts.authdomain
|
|
|
|
? 'user identity'
|
|
|
|
: 'user@domain.net';
|
2016-10-12 12:33:07 +00:00
|
|
|
|
2015-12-17 15:31:11 +00:00
|
|
|
return `
|
2017-10-10 23:31:40 +00:00
|
|
|
<input name="username" type="text"
|
2016-11-09 16:46:58 +00:00
|
|
|
class="input-control"
|
2016-10-12 12:33:07 +00:00
|
|
|
placeholder=${placeholder} autofocus>
|
2015-12-17 15:31:11 +00:00
|
|
|
<input name="password" type="password"
|
2016-11-09 16:46:58 +00:00
|
|
|
class="input-control"
|
2016-10-21 18:17:17 +00:00
|
|
|
data-i18n="[placeholder]dialog.userPassword">`;
|
2015-12-18 17:54:15 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Generate cancel button config for the dialog.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2015-12-18 17:54:15 +00:00
|
|
|
function cancelButton() {
|
|
|
|
return {
|
2017-10-12 23:02:29 +00:00
|
|
|
title: APP.translation.generateTranslationHTML('dialog.Cancel'),
|
2015-12-18 17:54:15 +00:00
|
|
|
value: false
|
|
|
|
};
|
2015-12-17 15:31:11 +00:00
|
|
|
}
|
2015-03-13 14:01:42 +00:00
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Auth dialog for JitsiConnection which supports retries.
|
|
|
|
* If no cancelCallback provided then there will be
|
|
|
|
* no cancel button on the dialog.
|
|
|
|
*
|
|
|
|
* @class LoginDialog
|
|
|
|
* @constructor
|
|
|
|
*
|
|
|
|
* @param {function(jid, password)} successCallback
|
|
|
|
* @param {function} [cancelCallback] callback to invoke if user canceled.
|
|
|
|
*/
|
|
|
|
function LoginDialog(successCallback, cancelCallback) {
|
2017-10-12 23:02:29 +00:00
|
|
|
const loginButtons = [ {
|
|
|
|
title: APP.translation.generateTranslationHTML('dialog.Ok'),
|
2015-12-18 17:54:15 +00:00
|
|
|
value: true
|
2017-10-12 23:02:29 +00:00
|
|
|
} ];
|
|
|
|
const finishedButtons = [ {
|
2016-10-21 17:11:22 +00:00
|
|
|
title: APP.translation.generateTranslationHTML('dialog.retry'),
|
2015-12-18 17:54:15 +00:00
|
|
|
value: 'retry'
|
2017-10-12 23:02:29 +00:00
|
|
|
} ];
|
2015-12-18 17:54:15 +00:00
|
|
|
|
|
|
|
// show "cancel" button only if cancelCallback provided
|
|
|
|
if (cancelCallback) {
|
|
|
|
loginButtons.push(cancelButton());
|
|
|
|
finishedButtons.push(cancelButton());
|
|
|
|
}
|
|
|
|
|
2017-10-20 17:05:30 +00:00
|
|
|
const states = {
|
2015-03-13 14:01:42 +00:00
|
|
|
login: {
|
2015-12-18 17:54:15 +00:00
|
|
|
buttons: loginButtons,
|
2015-03-13 14:01:42 +00:00
|
|
|
focus: ':input:first',
|
2017-10-20 17:05:30 +00:00
|
|
|
html: getPasswordInputHtml(),
|
|
|
|
titleKey: 'dialog.passwordRequired',
|
|
|
|
|
|
|
|
submit(e, v, m, f) { // eslint-disable-line max-params
|
2015-03-13 14:01:42 +00:00
|
|
|
e.preventDefault();
|
|
|
|
if (v) {
|
2017-10-12 23:02:29 +00:00
|
|
|
const jid = f.username;
|
|
|
|
const password = f.password;
|
|
|
|
|
2015-03-13 14:01:42 +00:00
|
|
|
if (jid && password) {
|
2017-10-20 17:05:30 +00:00
|
|
|
// eslint-disable-next-line no-use-before-define
|
2015-03-13 14:01:42 +00:00
|
|
|
connDialog.goToState('connecting');
|
2017-09-08 13:36:42 +00:00
|
|
|
successCallback(toJid(jid, config.hosts), password);
|
2015-03-13 14:01:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// User cancelled
|
2015-12-15 12:09:44 +00:00
|
|
|
cancelCallback();
|
2015-03-13 14:01:42 +00:00
|
|
|
}
|
2017-10-30 17:17:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
connecting: {
|
|
|
|
buttons: [],
|
|
|
|
defaultButton: 0,
|
|
|
|
html: '<div id="connectionStatus"></div>',
|
|
|
|
titleKey: 'dialog.connecting'
|
|
|
|
},
|
|
|
|
finished: {
|
|
|
|
buttons: finishedButtons,
|
|
|
|
defaultButton: 0,
|
|
|
|
html: '<div id="errorMessage"></div>',
|
|
|
|
titleKey: 'dialog.error',
|
|
|
|
|
|
|
|
submit(e, v) {
|
|
|
|
e.preventDefault();
|
|
|
|
if (v === 'retry') {
|
|
|
|
// eslint-disable-next-line no-use-before-define
|
|
|
|
connDialog.goToState('login');
|
|
|
|
} else {
|
|
|
|
// User cancelled
|
|
|
|
cancelCallback();
|
|
|
|
}
|
2015-03-13 14:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-10-20 17:05:30 +00:00
|
|
|
const connDialog = APP.UI.messageHandler.openDialogWithStates(
|
|
|
|
states,
|
|
|
|
{
|
|
|
|
closeText: '',
|
2018-12-28 17:37:29 +00:00
|
|
|
persistent: true,
|
|
|
|
zIndex: 1020
|
2017-10-20 17:05:30 +00:00
|
|
|
},
|
|
|
|
null
|
|
|
|
);
|
2015-03-13 14:01:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays error message in 'finished' state which allows either to cancel
|
|
|
|
* or retry.
|
2017-03-07 22:42:36 +00:00
|
|
|
* @param error the key to the error to be displayed.
|
2016-10-21 17:11:22 +00:00
|
|
|
* @param options the options to the error message (optional)
|
2015-03-13 14:01:42 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
this.displayError = function(error, options) {
|
2015-03-13 14:01:42 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const finishedState = connDialog.getState('finished');
|
2015-03-13 14:01:42 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const errorMessageElem = finishedState.find('#errorMessage');
|
2017-03-07 22:42:36 +00:00
|
|
|
|
|
|
|
let messageKey;
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2017-10-10 23:31:40 +00:00
|
|
|
if (error === JitsiConnectionErrors.PASSWORD_REQUIRED) {
|
2017-03-07 22:42:36 +00:00
|
|
|
// this is a password required error, as login window was already
|
|
|
|
// open once, this means username or password is wrong
|
|
|
|
messageKey = 'dialog.incorrectPassword';
|
2017-10-12 23:02:29 +00:00
|
|
|
} else {
|
2017-03-07 22:42:36 +00:00
|
|
|
messageKey = 'dialog.connectErrorWithMsg';
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
if (!options) {
|
|
|
|
options = {};// eslint-disable-line no-param-reassign
|
|
|
|
}
|
2017-03-07 22:42:36 +00:00
|
|
|
|
|
|
|
options.msg = error;
|
|
|
|
}
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
errorMessageElem.attr('data-i18n', messageKey);
|
2016-10-21 17:11:22 +00:00
|
|
|
|
|
|
|
APP.translation.translateElement($(errorMessageElem), options);
|
2015-03-13 14:01:42 +00:00
|
|
|
|
|
|
|
connDialog.goToState('finished');
|
|
|
|
};
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Show message as connection status.
|
2016-10-18 16:16:52 +00:00
|
|
|
* @param {string} messageKey the key to the message
|
2016-01-15 14:59:35 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
this.displayConnectionStatus = function(messageKey) {
|
|
|
|
const connectingState = connDialog.getState('connecting');
|
2015-12-29 14:41:24 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const connectionStatus = connectingState.find('#connectionStatus');
|
|
|
|
|
|
|
|
connectionStatus.attr('data-i18n', messageKey);
|
2016-10-21 17:11:22 +00:00
|
|
|
APP.translation.translateElement($(connectionStatus));
|
2015-12-29 14:41:24 +00:00
|
|
|
};
|
|
|
|
|
2015-03-13 14:01:42 +00:00
|
|
|
/**
|
|
|
|
* Closes LoginDialog.
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
this.close = function() {
|
2015-03-13 14:01:42 +00:00
|
|
|
connDialog.close();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
export default {
|
2015-03-13 14:01:42 +00:00
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Show new auth dialog for JitsiConnection.
|
|
|
|
*
|
|
|
|
* @param {function(jid, password)} successCallback
|
|
|
|
* @param {function} [cancelCallback] callback to invoke if user canceled.
|
|
|
|
*
|
|
|
|
* @returns {LoginDialog}
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
showAuthDialog(successCallback, cancelCallback) {
|
2016-01-15 14:59:35 +00:00
|
|
|
return new LoginDialog(successCallback, cancelCallback);
|
2015-12-15 12:09:44 +00:00
|
|
|
},
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
|
|
|
* Show notification that external auth is required (using provided url).
|
|
|
|
* @param {string} url URL to use for external auth.
|
|
|
|
* @param {function} callback callback to invoke when auth popup is closed.
|
|
|
|
* @returns auth dialog
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
showExternalAuthDialog(url, callback) {
|
|
|
|
const dialog = APP.UI.messageHandler.openCenteredPopup(
|
2015-12-15 12:09:44 +00:00
|
|
|
url, 910, 660,
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2015-12-15 12:09:44 +00:00
|
|
|
// On closed
|
|
|
|
callback
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!dialog) {
|
2017-11-03 19:05:03 +00:00
|
|
|
APP.UI.messageHandler.showWarning({
|
|
|
|
descriptionKey: 'dialog.popupError',
|
|
|
|
titleKey: 'dialog.popupErrorTitle'
|
|
|
|
});
|
2015-12-15 12:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return dialog;
|
2015-12-15 16:29:37 +00:00
|
|
|
},
|
|
|
|
|
2016-01-15 14:59:35 +00:00
|
|
|
/**
|
2017-09-18 07:09:43 +00:00
|
|
|
* Shows a notification that authentication is required to create the
|
|
|
|
* conference, so the local participant should authenticate or wait for a
|
|
|
|
* host.
|
|
|
|
*
|
|
|
|
* @param {string} room - The name of the conference.
|
|
|
|
* @param {function} onAuthNow - The callback to invoke if the local
|
|
|
|
* participant wants to authenticate.
|
2016-01-15 14:59:35 +00:00
|
|
|
* @returns dialog
|
|
|
|
*/
|
2017-09-18 07:09:43 +00:00
|
|
|
showAuthRequiredDialog(room, onAuthNow) {
|
|
|
|
const msg = APP.translation.generateTranslationHTML(
|
|
|
|
'[html]dialog.WaitForHostMsg',
|
|
|
|
{ room }
|
2015-12-15 16:29:37 +00:00
|
|
|
);
|
2017-09-18 07:09:43 +00:00
|
|
|
const buttonTxt = APP.translation.generateTranslationHTML(
|
|
|
|
'dialog.IamHost'
|
2015-12-15 16:29:37 +00:00
|
|
|
);
|
2017-10-12 23:02:29 +00:00
|
|
|
const buttons = [ {
|
2017-09-18 07:09:43 +00:00
|
|
|
title: buttonTxt,
|
|
|
|
value: 'authNow'
|
2017-10-12 23:02:29 +00:00
|
|
|
} ];
|
2015-12-15 16:29:37 +00:00
|
|
|
|
|
|
|
return APP.UI.messageHandler.openDialog(
|
2017-09-18 07:09:43 +00:00
|
|
|
'dialog.WaitingForHost',
|
2015-12-15 16:29:37 +00:00
|
|
|
msg,
|
|
|
|
true,
|
|
|
|
buttons,
|
2017-09-18 07:09:43 +00:00
|
|
|
(e, submitValue) => {
|
|
|
|
// Do not close the dialog yet.
|
2015-12-17 15:31:11 +00:00
|
|
|
e.preventDefault();
|
2015-12-15 16:29:37 +00:00
|
|
|
|
2017-09-18 07:09:43 +00:00
|
|
|
// Open login popup.
|
2015-12-15 16:29:37 +00:00
|
|
|
if (submitValue === 'authNow') {
|
|
|
|
onAuthNow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2015-03-13 14:01:42 +00:00
|
|
|
}
|
|
|
|
};
|