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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. if(error) //error=undefined if external connect is disabled.
  39. console.warn(error);
  40. // Sets that global variable to be used later by connect method in
  41. // connection.js
  42. window.XMPPAttachInfo = {
  43. status: "error"
  44. };
  45. checkForConnectHandlerAndConnect();
  46. }
  47. if(!url || !window.createConnectionExternally) {
  48. error_callback();
  49. return;
  50. }
  51. var room_name = getRoomName();
  52. if(!room_name) {
  53. error_callback();
  54. return;
  55. }
  56. url += "?room=" + room_name;
  57. var token = buildToken();
  58. if(token)
  59. url += "&token=" + token;
  60. createConnectionExternally(url, function(connectionInfo) {
  61. // Sets that global variable to be used later by connect method in
  62. // connection.js
  63. window.XMPPAttachInfo = {
  64. status: "success",
  65. data: connectionInfo
  66. };
  67. checkForConnectHandlerAndConnect();
  68. }, error_callback);
  69. })();