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.

do_external_connect.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* global config, createConnectionExternally */
  2. import getRoomName from '../react/features/base/config/getRoomName';
  3. import parseURLParams from '../react/features/base/config/parseURLParams';
  4. /**
  5. * Implements external connect using createConnectionExternally function defined
  6. * in external_connect.js for Jitsi Meet. Parses the room name and JSON Web
  7. * Token (JWT) from the URL and executes createConnectionExternally.
  8. *
  9. * NOTE: If you are using lib-jitsi-meet without Jitsi Meet, you should use this
  10. * file as reference only because the implementation is Jitsi Meet-specific.
  11. *
  12. * NOTE: For optimal results this file should be included right after
  13. * external_connect.js.
  14. */
  15. if (typeof createConnectionExternally === 'function') {
  16. // URL params have higher proirity than config params.
  17. let url
  18. = parseURLParams(window.location, true, 'hash')[
  19. 'config.externalConnectUrl']
  20. || config.externalConnectUrl;
  21. let roomName;
  22. if (url && (roomName = getRoomName())) {
  23. url += `?room=${roomName}`;
  24. const token = parseURLParams(window.location, true, 'search').jwt;
  25. if (token) {
  26. url += `&token=${token}`;
  27. }
  28. createConnectionExternally(
  29. url,
  30. connectionInfo => {
  31. // Sets that global variable to be used later by connect method
  32. // in connection.js.
  33. window.XMPPAttachInfo = {
  34. status: 'success',
  35. data: connectionInfo
  36. };
  37. checkForConnectHandlerAndConnect();
  38. },
  39. errorCallback);
  40. } else {
  41. errorCallback();
  42. }
  43. } else {
  44. errorCallback();
  45. }
  46. /**
  47. * Check if connect from connection.js was executed and executes the handler
  48. * that is going to finish the connect work.
  49. *
  50. * @returns {void}
  51. */
  52. function checkForConnectHandlerAndConnect() {
  53. window.APP
  54. && window.APP.connect.status === 'ready'
  55. && window.APP.connect.handler();
  56. }
  57. /**
  58. * Implements a callback to be invoked if anything goes wrong.
  59. *
  60. * @param {Error} error - The specifics of what went wrong.
  61. * @returns {void}
  62. */
  63. function errorCallback(error) {
  64. // The value of error is undefined if external connect is disabled.
  65. error && console.warn(error);
  66. // Sets that global variable to be used later by connect method in
  67. // connection.js.
  68. window.XMPPAttachInfo = {
  69. status: 'error'
  70. };
  71. checkForConnectHandlerAndConnect();
  72. }