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

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