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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* global JitsiMeetJS, APP */
  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. loginDialog.displayConnectionStatus(
  42. APP.translation.translateString('connection.FETCH_SESSION_ID')
  43. );
  44. newRoom.room.moderator.authenticate().then(function () {
  45. connection.disconnect();
  46. loginDialog.displayConnectionStatus(
  47. APP.translation.translateString('connection.GOT_SESSION_ID')
  48. );
  49. if (room.isJoined()) {
  50. // just reallocate focus if already joined
  51. room.room.moderator.allocateConferenceFocus();
  52. } else {
  53. // or join
  54. room.join(lockPassword);
  55. }
  56. loginDialog.close();
  57. }).catch(function (error, code) {
  58. connection.disconnect();
  59. console.error('Auth on the fly failed', error);
  60. let errorMsg = APP.translation.translateString(
  61. 'connection.GET_SESSION_ID_ERROR'
  62. );
  63. loginDialog.displayError(errorMsg + code);
  64. });
  65. }, function (err) {
  66. loginDialog.displayError(err);
  67. });
  68. }, function () { // user canceled
  69. loginDialog.close();
  70. });
  71. }
  72. function authenticate (room, lockPassword) {
  73. if (room.isExternalAuthEnabled()) {
  74. doExternalAuth(room, lockPassword);
  75. } else {
  76. doXmppAuth();
  77. }
  78. }
  79. function requireAuth(roomName) {
  80. if (authRequiredDialog) {
  81. return;
  82. }
  83. authRequiredDialog = LoginDialog.showAuthRequiredDialog(
  84. roomName, authenticate
  85. );
  86. }
  87. function closeAuth() {
  88. if (externalAuthWindow) {
  89. externalAuthWindow.close();
  90. externalAuthWindow = null;
  91. }
  92. if (authRequiredDialog) {
  93. authRequiredDialog.close();
  94. authRequiredDialog = null;
  95. }
  96. }
  97. export default {
  98. authenticate,
  99. requireAuth,
  100. closeAuth
  101. };