Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

connection.js 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* global APP, JitsiMeetJS, config */
  2. //FIXME:
  3. import LoginDialog from './modules/UI/authentication/LoginDialog';
  4. const ConnectionEvents = JitsiMeetJS.events.connection;
  5. const ConnectionErrors = JitsiMeetJS.errors.connection;
  6. function connect(id, password) {
  7. let connection = new JitsiMeetJS.JitsiConnection(null, null, config);
  8. return new Promise(function (resolve, reject) {
  9. connection.addEventListener(
  10. ConnectionEvents.CONNECTION_ESTABLISHED, handleConnectionEstablished
  11. );
  12. connection.addEventListener(
  13. ConnectionEvents.CONNECTION_FAILED, handleConnectionFailed
  14. );
  15. function unsubscribe() {
  16. connection.removeEventListener(
  17. ConnectionEvents.CONNECTION_ESTABLISHED,
  18. handleConnectionEstablished
  19. );
  20. connection.removeEventListener(
  21. ConnectionEvents.CONNECTION_FAILED,
  22. handleConnectionFailed
  23. );
  24. }
  25. function handleConnectionEstablished() {
  26. unsubscribe();
  27. resolve(connection);
  28. }
  29. function handleConnectionFailed(err) {
  30. unsubscribe();
  31. console.error("CONNECTION FAILED:", err);
  32. reject(err);
  33. }
  34. connection.connect({id, password});
  35. });
  36. }
  37. function requestAuth() {
  38. return new Promise(function (resolve, reject) {
  39. let authDialog = LoginDialog.showAuthDialog(
  40. function (id, password) {
  41. connect(id, password).then(function (connection) {
  42. authDialog.close();
  43. resolve(connection);
  44. }, function (err) {
  45. if (err === ConnectionErrors.PASSWORD_REQUIRED) {
  46. authDialog.displayError(err);
  47. } else {
  48. authDialog.close();
  49. reject(err);
  50. }
  51. });
  52. }
  53. );
  54. });
  55. }
  56. export function openConnection({id, password, retry}) {
  57. return connect(id, password).catch(function (err) {
  58. if (!retry) {
  59. throw err;
  60. }
  61. if (err === ConnectionErrors.PASSWORD_REQUIRED) {
  62. // do not retry if token is not valid
  63. if (config.token) {
  64. throw err;
  65. } else {
  66. return requestAuth();
  67. }
  68. } else {
  69. throw err;
  70. }
  71. });
  72. }