您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Authentication.js 2.9KB

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