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

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