Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Add support for jiconop #2504

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ doc/example/libs/*
# not seem to be a reason why we will want to risk being inconsistent with our
# remaining JavaScript source code.
!.eslintrc.js

# Source code written in ES5 which is not processed through Babel.
connection_optimization/external_connect.js
69 changes: 69 additions & 0 deletions connection_optimization/external_connect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Requests the given webservice that will create the connection and will return
* the necessary details(rid, sid and jid) to attach to this connection and
* start using it. This script can be used for optimizing the connection startup
* time. The function will send AJAX request to a webservice that should
* create the bosh session much faster than the client because the webservice
* can be started on the same machine as the XMPP serever.
*
* NOTE: It's vert important to execute this function as early as you can for
* optimal results.
*
* @param webserviceUrl the url for the web service that is going to create the
* connection.
* @param successCallback callback function called with the result of the AJAX
* request if the request was successfull. The callback will receive one
* parameter which will be JS Object with properties - rid, sid and jid. This
* result should be passed to JitsiConnection.attach method in order to use that
* connection.
* @param error_callback callback function called the AJAX request fail. This
* callback is going to receive one parameter which is going to be JS error
* object with a reason for failure in it.
*/

console.log('external_connect.js loaded');
function createConnectionExternally( // eslint-disable-line no-unused-vars
webserviceUrl,
successCallback,
error_callback) {
if (!window.XMLHttpRequest) {
error_callback(new Error('XMLHttpRequest is not supported!'));
return;
}

var HTTP_STATUS_OK = 200;

var xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function() {
if (xhttp.readyState == xhttp.DONE) {
var now = window.connectionTimes['external_connect.done']
= window.performance.now();
console.log('(TIME) external connect XHR done:\t', now);
if (xhttp.status == HTTP_STATUS_OK) {
try {
var data = JSON.parse(xhttp.responseText);
successCallback(data);
} catch (e) {
error_callback(e);
}
} else {
error_callback(new Error('XMLHttpRequest error. Status: '
+ xhttp.status + '. Error message: ' + xhttp.statusText));
}
}
};

xhttp.open('GET', webserviceUrl, true);

// Fixes external connect for IE
// The timeout property may be set only after calling the open() method
// and before calling the send() method.
xhttp.timeout = 3000;

window.connectionTimes = {};
var now = window.connectionTimes['external_connect.sending']
= window.performance.now();
console.log('(TIME) Sending external connect XHR:\t', now);
xhttp.send();
}
2 changes: 2 additions & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ declare global {
interface Window {
connectionTimes: any;
}
// function named createConnectionExternally
function createConnectionExternally(): void;
}
Loading