You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Authentication.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Initial "authentication required" dialog */
  2. var authDialog = null;
  3. /* Loop retry ID that wits for other user to create the room */
  4. var authRetryId = null;
  5. var authenticationWindow = null;
  6. var Authentication = {
  7. openAuthenticationDialog: function (roomName, intervalCallback, callback) {
  8. // This is the loop that will wait for the room to be created by
  9. // someone else. 'auth_required.moderator' will bring us back here.
  10. authRetryId = window.setTimeout(intervalCallback , 5000);
  11. // Show prompt only if it's not open
  12. if (authDialog !== null) {
  13. return;
  14. }
  15. // extract room name from 'room@muc.server.net'
  16. var room = roomName.substr(0, roomName.indexOf('@'));
  17. var title = APP.translation.generateTranslatonHTML("dialog.Stop");
  18. var msg = APP.translation.generateTranslatonHTML("dialog.AuthMsg",
  19. {room: room});
  20. var button = APP.translation.generateTranslatonHTML(
  21. "dialog.Authenticate");
  22. var buttons = {};
  23. buttons.authenticate = {title: button, value: "authNow"};
  24. authDialog = APP.UI.messageHandler.openDialog(
  25. title,
  26. msg,
  27. true,
  28. buttons,
  29. function (onSubmitEvent, submitValue) {
  30. // Do not close the dialog yet
  31. onSubmitEvent.preventDefault();
  32. // Open login popup
  33. if (submitValue === 'authNow') {
  34. callback();
  35. }
  36. }
  37. );
  38. },
  39. closeAuthenticationWindow:function () {
  40. if (authenticationWindow) {
  41. authenticationWindow.close();
  42. authenticationWindow = null;
  43. }
  44. },
  45. focusAuthenticationWindow: function () {
  46. // If auth window exists just bring it to the front
  47. if (authenticationWindow) {
  48. authenticationWindow.focus();
  49. return;
  50. }
  51. },
  52. closeAuthenticationDialog: function () {
  53. // Close authentication dialog if opened
  54. if (authDialog) {
  55. APP.UI.messageHandler.closeDialog();
  56. authDialog = null;
  57. }
  58. },
  59. createAuthenticationWindow: function (callback, url) {
  60. authenticationWindow = APP.UI.messageHandler.openCenteredPopup(
  61. url, 910, 660,
  62. // On closed
  63. function () {
  64. // Close authentication dialog if opened
  65. if (authDialog) {
  66. messageHandler.closeDialog();
  67. authDialog = null;
  68. }
  69. callback();
  70. authenticationWindow = null;
  71. });
  72. return authenticationWindow;
  73. },
  74. stopInterval: function () {
  75. // Clear retry interval, so that we don't call 'doJoinAfterFocus' twice
  76. if (authRetryId) {
  77. window.clearTimeout(authRetryId);
  78. authRetryId = null;
  79. }
  80. }
  81. };
  82. module.exports = Authentication;