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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. * Gets the token from the URL.
  16. */
  17. function buildToken(){
  18. var params = getConfigParamsFromUrl();
  19. return params["config.token"] || config.token;
  20. }
  21. /**
  22. * Executes createConnectionExternally function.
  23. */
  24. (function () {
  25. // FIXME: Add implementation for changing that config from the url for
  26. // consistency
  27. var url = config.externalConnectUrl;
  28. /**
  29. * Check if connect from connection.js was executed and executes the handler
  30. * that is going to finish the connect work.
  31. */
  32. function checkForConnectHandlerAndConnect() {
  33. if(window.APP && window.APP.connect.status === "ready") {
  34. window.APP.connect.handler();
  35. }
  36. }
  37. function error_callback(error){
  38. console.warn(error);
  39. // Sets that global variable to be used later by connect method in
  40. // connection.js
  41. window.XMPPAttachInfo = {
  42. status: "error"
  43. };
  44. checkForConnectHandlerAndConnect();
  45. }
  46. if(!url || !window.createConnectionExternally) {
  47. error_callback();
  48. return;
  49. }
  50. var room_name = getRoomName();
  51. if(!room_name) {
  52. error_callback();
  53. return;
  54. }
  55. url += "?room=" + room_name;
  56. var token = buildToken();
  57. if(token)
  58. url += "&token=" + token;
  59. createConnectionExternally(url, function(connectionInfo) {
  60. // Sets that global variable to be used later by connect method in
  61. // connection.js
  62. window.XMPPAttachInfo = {
  63. status: "success",
  64. data: connectionInfo
  65. };
  66. checkForConnectHandlerAndConnect();
  67. }, error_callback);
  68. })();