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 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. "Stop");
  19. var defMsg = 'Authentication is required to create room:<br/><b>' +
  20. room +
  21. '</b></br> You can either authenticate to create the room or ' +
  22. 'just wait for someone else to do so.';
  23. var msg = APP.translation.generateTranslatonHTML("dialog.AuthMsg",
  24. defMsg, {room: room});
  25. var button = APP.translation.generateTranslatonHTML(
  26. "dialog.Authenticate", "Authenticate");
  27. var buttons = {};
  28. buttons.authenticate = {title: button, value: "authNow"};
  29. authDialog = APP.UI.messageHandler.openDialog(
  30. title,
  31. msg,
  32. true,
  33. buttons,
  34. function (onSubmitEvent, submitValue) {
  35. // Do not close the dialog yet
  36. onSubmitEvent.preventDefault();
  37. // Open login popup
  38. if (submitValue === 'authNow') {
  39. callback();
  40. }
  41. }
  42. );
  43. },
  44. closeAuthenticationWindow:function () {
  45. if (authenticationWindow) {
  46. authenticationWindow.close();
  47. authenticationWindow = null;
  48. }
  49. },
  50. focusAuthenticationWindow: function () {
  51. // If auth window exists just bring it to the front
  52. if (authenticationWindow) {
  53. authenticationWindow.focus();
  54. return;
  55. }
  56. },
  57. closeAuthenticationDialog: function () {
  58. // Close authentication dialog if opened
  59. if (authDialog) {
  60. APP.UI.messageHandler.closeDialog();
  61. authDialog = null;
  62. }
  63. },
  64. createAuthenticationWindow: function (callback, url) {
  65. authenticationWindow = APP.UI.messageHandler.openCenteredPopup(
  66. url, 910, 660,
  67. // On closed
  68. function () {
  69. // Close authentication dialog if opened
  70. if (authDialog) {
  71. messageHandler.closeDialog();
  72. authDialog = null;
  73. }
  74. callback();
  75. authenticationWindow = null;
  76. });
  77. return authenticationWindow;
  78. },
  79. stopInterval: function () {
  80. // Clear retry interval, so that we don't call 'doJoinAfterFocus' twice
  81. if (authRetryId) {
  82. window.clearTimeout(authRetryId);
  83. authRetryId = null;
  84. }
  85. }
  86. };
  87. module.exports = Authentication;