Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

external_connect.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * Requests the given webservice that will create the connection and will return
  3. * the necessary details(rid, sid and jid) to attach to this connection and
  4. * start using it. This script can be used for optimizing the connection startup
  5. * time. The function will send AJAX request to a webservice that should
  6. * create the bosh session much faster than the client because the webservice
  7. * can be started on the same machine as the XMPP serever.
  8. *
  9. * NOTE: It's vert important to execute this function as early as you can for
  10. * optimal results.
  11. *
  12. * @param webserviceUrl the url for the web service that is going to create the
  13. * connection.
  14. * @param success_callback callback function called with the result of the AJAX
  15. * request if the request was successfull. The callback will receive one
  16. * parameter which will be JS Object with properties - rid, sid and jid. This
  17. * result should be passed to JitsiConnection.attach method in order to use that
  18. * connection.
  19. * @param error_callback callback function called the AJAX request fail. This
  20. * callback is going to receive one parameter which is going to be JS error
  21. * object with a reason for failure in it.
  22. */
  23. function createConnectionExternally(webserviceUrl, success_callback,
  24. error_callback) {
  25. if (!window.XMLHttpRequest) {
  26. error_callback(new Error("XMLHttpRequest is not supported!"));
  27. return;
  28. }
  29. var HTTP_STATUS_OK = 200;
  30. var xhttp = new XMLHttpRequest();
  31. xhttp.onreadystatechange = function() {
  32. if (xhttp.readyState == xhttp.DONE) {
  33. if (xhttp.status == HTTP_STATUS_OK) {
  34. try {
  35. var data = JSON.parse(xhttp.responseText);
  36. success_callback(data);
  37. } catch (e) {
  38. error_callback(e);
  39. }
  40. } else {
  41. error_callback(new Error("XMLHttpRequest error. Status: " +
  42. xhttp.status + ". Error message: " + xhttp.statusText));
  43. }
  44. }
  45. };
  46. xhttp.open("GET", webserviceUrl, true);
  47. xhttp.send();
  48. }