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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* global config, getRoomName, getConfigParamsFromUrl */
  2. /* global createConnectionExternally */
  3. /**
  4. * Implements extrnal connect using createConnectionExtenally function defined
  5. * in external_connect.js for Jitsi Meet. Parses the room name and token from
  6. * the url and executes createConnectionExtenally.
  7. *
  8. * NOTE: If you are using lib-jitsi-meet without Jitsi Meet you should use this
  9. * file as reference only because the implementation is Jitsi Meet specific.
  10. *
  11. * NOTE: For optimal results this file should be included right after
  12. * exrnal_connect.js.
  13. */
  14. /**
  15. * Executes createConnectionExternally function.
  16. */
  17. (function () {
  18. var hashParams = getConfigParamsFromUrl("hash", true);
  19. var searchParams = getConfigParamsFromUrl("search", true);
  20. //Url params have higher proirity than config params
  21. var url = config.externalConnectUrl;
  22. if(hashParams.hasOwnProperty('config.externalConnectUrl'))
  23. url = hashParams["config.externalConnectUrl"];
  24. /**
  25. * Check if connect from connection.js was executed and executes the handler
  26. * that is going to finish the connect work.
  27. */
  28. function checkForConnectHandlerAndConnect() {
  29. if(window.APP && window.APP.connect.status === "ready") {
  30. window.APP.connect.handler();
  31. }
  32. }
  33. function error_callback(error){
  34. if(error) //error=undefined if external connect is disabled.
  35. console.warn(error);
  36. // Sets that global variable to be used later by connect method in
  37. // connection.js
  38. window.XMPPAttachInfo = {
  39. status: "error"
  40. };
  41. checkForConnectHandlerAndConnect();
  42. }
  43. if(!url || !window.createConnectionExternally) {
  44. error_callback();
  45. return;
  46. }
  47. var room_name = getRoomName();
  48. if(!room_name) {
  49. error_callback();
  50. return;
  51. }
  52. url += "?room=" + room_name;
  53. var token = hashParams["config.token"] || config.token ||
  54. searchParams.jwt;
  55. if(token)
  56. url += "&token=" + token;
  57. createConnectionExternally(url, function(connectionInfo) {
  58. // Sets that global variable to be used later by connect method in
  59. // connection.js
  60. window.XMPPAttachInfo = {
  61. status: "success",
  62. data: connectionInfo
  63. };
  64. checkForConnectHandlerAndConnect();
  65. }, error_callback);
  66. })();