Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

AuthHandler.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. });
  50. }, function (err) {
  51. loginDialog.displayError(err);
  52. });
  53. }, function () { // user canceled
  54. loginDialog.close();
  55. });
  56. }
  57. function authenticate (room, lockPassword) {
  58. if (room.isExternalAuthEnabled()) {
  59. doExternalAuth(room, lockPassword);
  60. } else {
  61. doXmppAuth();
  62. }
  63. }
  64. function requireAuth(roomName) {
  65. if (authRequiredDialog) {
  66. return;
  67. }
  68. authRequiredDialog = LoginDialog.showAuthRequiredDialog(
  69. roomName, authenticate
  70. );
  71. }
  72. function closeAuth() {
  73. if (externalAuthWindow) {
  74. externalAuthWindow.close();
  75. externalAuthWindow = null;
  76. }
  77. if (authRequiredDialog) {
  78. authRequiredDialog.close();
  79. authRequiredDialog = null;
  80. }
  81. }
  82. export default {
  83. authenticate,
  84. requireAuth,
  85. closeAuth
  86. };