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.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 priority than config params.
  17. let url
  18. = parseURLParams(window.location, true, 'hash')[
  19. 'config.externalConnectUrl']
  20. || config.externalConnectUrl;
  21. const isRecorder
  22. = parseURLParams(window.location, true, 'hash')['config.iAmRecorder'];
  23. let roomName;
  24. if (url && (roomName = getRoomName()) && !isRecorder) {
  25. url += `?room=${roomName}`;
  26. const token = parseURLParams(window.location, true, 'search').jwt;
  27. if (token) {
  28. url += `&token=${token}`;
  29. }
  30. createConnectionExternally(
  31. url,
  32. connectionInfo => {
  33. // Sets that global variable to be used later by connect method
  34. // in connection.js.
  35. window.XMPPAttachInfo = {
  36. status: 'success',
  37. data: connectionInfo
  38. };
  39. checkForConnectHandlerAndConnect();
  40. },
  41. errorCallback);
  42. } else {
  43. errorCallback();
  44. }
  45. } else {
  46. errorCallback();
  47. }
  48. /**
  49. * Check if connect from connection.js was executed and executes the handler
  50. * that is going to finish the connect work.
  51. *
  52. * @returns {void}
  53. */
  54. function checkForConnectHandlerAndConnect() {
  55. window.APP
  56. && window.APP.connect.status === 'ready'
  57. && window.APP.connect.handler();
  58. }
  59. /**
  60. * Implements a callback to be invoked if anything goes wrong.
  61. *
  62. * @param {Error} error - The specifics of what went wrong.
  63. * @returns {void}
  64. */
  65. function errorCallback(error) {
  66. // The value of error is undefined if external connect is disabled.
  67. error && console.warn(error);
  68. // Sets that global variable to be used later by connect method in
  69. // connection.js.
  70. window.XMPPAttachInfo = {
  71. status: 'error'
  72. };
  73. checkForConnectHandlerAndConnect();
  74. }