Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

LoginDialog.js 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /* global $, APP, config */
  2. import { toJid } from '../../../react/features/base/connection';
  3. import {
  4. JitsiConnectionErrors
  5. } from '../../../react/features/base/lib-jitsi-meet';
  6. /**
  7. * Build html for "password required" dialog.
  8. * @returns {string} html string
  9. */
  10. function getPasswordInputHtml() {
  11. const placeholder = config.hosts.authdomain
  12. ? 'user identity'
  13. : 'user@domain.net';
  14. return `
  15. <input name="username" type="text"
  16. class="input-control"
  17. placeholder=${placeholder} autofocus>
  18. <input name="password" type="password"
  19. class="input-control"
  20. data-i18n="[placeholder]dialog.userPassword">`;
  21. }
  22. /**
  23. * Generate cancel button config for the dialog.
  24. * @returns {Object}
  25. */
  26. function cancelButton() {
  27. return {
  28. title: APP.translation.generateTranslationHTML('dialog.Cancel'),
  29. value: false
  30. };
  31. }
  32. /**
  33. * Auth dialog for JitsiConnection which supports retries.
  34. * If no cancelCallback provided then there will be
  35. * no cancel button on the dialog.
  36. *
  37. * @class LoginDialog
  38. * @constructor
  39. *
  40. * @param {function(jid, password)} successCallback
  41. * @param {function} [cancelCallback] callback to invoke if user canceled.
  42. */
  43. function LoginDialog(successCallback, cancelCallback) {
  44. const loginButtons = [ {
  45. title: APP.translation.generateTranslationHTML('dialog.Ok'),
  46. value: true
  47. } ];
  48. const finishedButtons = [ {
  49. title: APP.translation.generateTranslationHTML('dialog.retry'),
  50. value: 'retry'
  51. } ];
  52. // show "cancel" button only if cancelCallback provided
  53. if (cancelCallback) {
  54. loginButtons.push(cancelButton());
  55. finishedButtons.push(cancelButton());
  56. }
  57. const connDialog = APP.UI.messageHandler.openDialogWithStates(
  58. states, // eslint-disable-line no-use-before-define
  59. {
  60. persistent: true,
  61. closeText: ''
  62. },
  63. null
  64. );
  65. const states = {
  66. login: {
  67. titleKey: 'dialog.passwordRequired',
  68. html: getPasswordInputHtml(),
  69. buttons: loginButtons,
  70. focus: ':input:first',
  71. // eslint-disable-next-line max-params
  72. submit(e, v, m, f) {
  73. e.preventDefault();
  74. if (v) {
  75. const jid = f.username;
  76. const password = f.password;
  77. if (jid && password) {
  78. connDialog.goToState('connecting');
  79. successCallback(toJid(jid, config.hosts), password);
  80. }
  81. } else {
  82. // User cancelled
  83. cancelCallback();
  84. }
  85. }
  86. },
  87. connecting: {
  88. titleKey: 'dialog.connecting',
  89. html: '<div id="connectionStatus"></div>',
  90. buttons: [],
  91. defaultButton: 0
  92. },
  93. finished: {
  94. titleKey: 'dialog.error',
  95. html: '<div id="errorMessage"></div>',
  96. buttons: finishedButtons,
  97. defaultButton: 0,
  98. submit(e, v) {
  99. e.preventDefault();
  100. if (v === 'retry') {
  101. connDialog.goToState('login');
  102. } else {
  103. // User cancelled
  104. cancelCallback();
  105. }
  106. }
  107. }
  108. };
  109. /**
  110. * Displays error message in 'finished' state which allows either to cancel
  111. * or retry.
  112. * @param error the key to the error to be displayed.
  113. * @param options the options to the error message (optional)
  114. */
  115. this.displayError = function(error, options) {
  116. const finishedState = connDialog.getState('finished');
  117. const errorMessageElem = finishedState.find('#errorMessage');
  118. let messageKey;
  119. if (error === JitsiConnectionErrors.PASSWORD_REQUIRED) {
  120. // this is a password required error, as login window was already
  121. // open once, this means username or password is wrong
  122. messageKey = 'dialog.incorrectPassword';
  123. } else {
  124. messageKey = 'dialog.connectErrorWithMsg';
  125. if (!options) {
  126. options = {};// eslint-disable-line no-param-reassign
  127. }
  128. options.msg = error;
  129. }
  130. errorMessageElem.attr('data-i18n', messageKey);
  131. APP.translation.translateElement($(errorMessageElem), options);
  132. connDialog.goToState('finished');
  133. };
  134. /**
  135. * Show message as connection status.
  136. * @param {string} messageKey the key to the message
  137. */
  138. this.displayConnectionStatus = function(messageKey) {
  139. const connectingState = connDialog.getState('connecting');
  140. const connectionStatus = connectingState.find('#connectionStatus');
  141. connectionStatus.attr('data-i18n', messageKey);
  142. APP.translation.translateElement($(connectionStatus));
  143. };
  144. /**
  145. * Closes LoginDialog.
  146. */
  147. this.close = function() {
  148. connDialog.close();
  149. };
  150. }
  151. export default {
  152. /**
  153. * Show new auth dialog for JitsiConnection.
  154. *
  155. * @param {function(jid, password)} successCallback
  156. * @param {function} [cancelCallback] callback to invoke if user canceled.
  157. *
  158. * @returns {LoginDialog}
  159. */
  160. showAuthDialog(successCallback, cancelCallback) {
  161. return new LoginDialog(successCallback, cancelCallback);
  162. },
  163. /**
  164. * Show notification that external auth is required (using provided url).
  165. * @param {string} url URL to use for external auth.
  166. * @param {function} callback callback to invoke when auth popup is closed.
  167. * @returns auth dialog
  168. */
  169. showExternalAuthDialog(url, callback) {
  170. const dialog = APP.UI.messageHandler.openCenteredPopup(
  171. url, 910, 660,
  172. // On closed
  173. callback
  174. );
  175. if (!dialog) {
  176. APP.UI.messageHandler.openMessageDialog(null, 'dialog.popupError');
  177. }
  178. return dialog;
  179. },
  180. /**
  181. * Shows a notification that authentication is required to create the
  182. * conference, so the local participant should authenticate or wait for a
  183. * host.
  184. *
  185. * @param {string} room - The name of the conference.
  186. * @param {function} onAuthNow - The callback to invoke if the local
  187. * participant wants to authenticate.
  188. * @returns dialog
  189. */
  190. showAuthRequiredDialog(room, onAuthNow) {
  191. const msg = APP.translation.generateTranslationHTML(
  192. '[html]dialog.WaitForHostMsg',
  193. { room }
  194. );
  195. const buttonTxt = APP.translation.generateTranslationHTML(
  196. 'dialog.IamHost'
  197. );
  198. const buttons = [ {
  199. title: buttonTxt,
  200. value: 'authNow'
  201. } ];
  202. return APP.UI.messageHandler.openDialog(
  203. 'dialog.WaitingForHost',
  204. msg,
  205. true,
  206. buttons,
  207. (e, submitValue) => {
  208. // Do not close the dialog yet.
  209. e.preventDefault();
  210. // Open login popup.
  211. if (submitValue === 'authNow') {
  212. onAuthNow();
  213. }
  214. }
  215. );
  216. }
  217. };