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.

AuthHandler.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* global JitsiMeetJS */
  2. import LoginDialog from './UI/authentication/LoginDialog';
  3. import UIEvents from '../service/UI/UIEvents';
  4. import UIUtil from './UI/util/UIUtil';
  5. import {openConnection} from './connection';
  6. const ConferenceEvents = JitsiMeetJS.events.conference;
  7. let externalAuthWindow;
  8. let authRequiredDialog;
  9. function doExternalAuth (room, lockPassword) {
  10. if (externalAuthWindow) {
  11. externalAuthWindow.focus();
  12. return;
  13. }
  14. if (room.isJoined()) {
  15. room.getExternalAuthUrl(true).then(function (url) {
  16. externalAuthWindow = LoginDialog.showExternalAuthDialog(
  17. url,
  18. function () {
  19. externalAuthWindow = null;
  20. room.join(lockPassword);
  21. }
  22. );
  23. });
  24. } else {
  25. // If conference has not been started yet
  26. // then redirect to login page
  27. room.getExternalAuthUrl().then(UIUtil.redirect);
  28. }
  29. }
  30. function doXmppAuth (room, lockPassword) {
  31. let loginDialog = LoginDialog.showAuthDialog(function (id, password) {
  32. // auth "on the fly":
  33. // 1. open new connection with proper id and password
  34. // 2. connect to the room
  35. // (this will store sessionId in the localStorage)
  36. // 3. close new connection
  37. // 4. reallocate focus in current room
  38. openConnection({id, password}).then(function (connection) {
  39. // open room
  40. let newRoom = connection.initJitsiConference(room.getName());
  41. newRoom.on(ConferenceEvents.CONFERENCE_FAILED, function (err) {
  42. connection.disconnect();
  43. loginDialog.displayError(err);
  44. });
  45. // FIXME finish "on the fly" auth
  46. room.room.moderator.allocateConferenceFocus(function () {
  47. connection.disconnect();
  48. loginDialog.close();
  49. room.join(lockPassword);
  50. });
  51. }, function (err) {
  52. loginDialog.displayError(err);
  53. });
  54. }, function () { // user canceled
  55. loginDialog.close();
  56. });
  57. }
  58. function authenticate (room, lockPassword) {
  59. if (room.isExternalAuthEnabled()) {
  60. doExternalAuth(room, lockPassword);
  61. } else {
  62. doXmppAuth();
  63. }
  64. }
  65. function requireAuth(roomName) {
  66. if (authRequiredDialog) {
  67. return;
  68. }
  69. authRequiredDialog = LoginDialog.showAuthRequiredDialog(
  70. roomName, authenticate
  71. );
  72. }
  73. function closeAuth() {
  74. if (externalAuthWindow) {
  75. externalAuthWindow.close();
  76. externalAuthWindow = null;
  77. }
  78. if (authRequiredDialog) {
  79. authRequiredDialog.close();
  80. authRequiredDialog = null;
  81. }
  82. }
  83. export default {
  84. authenticate,
  85. requireAuth,
  86. closeAuth
  87. };