[Pkg-javascript-commits] [sockjs-client] 301/434: Use new detectProtocols method to detect protocols.
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:21 UTC 2014
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch master
in repository sockjs-client.
commit 832ced3b0f99fc4dc8065634d29262d099366a26
Author: Marek Majkowski <majek04 at gmail.com>
Date: Fri Jan 13 15:39:03 2012 +0000
Use new detectProtocols method to detect protocols.
---
lib/sockjs.js | 51 ++++++++++++++++++++++++---------------------------
lib/utils.js | 5 +++++
tests/config.js | 6 +++++-
3 files changed, 34 insertions(+), 28 deletions(-)
diff --git a/lib/sockjs.js b/lib/sockjs.js
index 07f7ee0..cccf846 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -1,4 +1,4 @@
-var SockJS = function(url, protocols, options) {
+var SockJS = function(url, protocols_whitelist, options) {
var that = this;
that._options = {devel: false, debug: false, info: undefined};
if (options) {
@@ -6,33 +6,27 @@ var SockJS = function(url, protocols, options) {
}
that._base_url = utils.amendUrl(url);
that._server = that._options.server || utils.random_number_string(1000);
- that._protocols = ['websocket',
- 'xhr-streaming',
- 'iframe-eventsource',
- 'iframe-htmlfile',
- 'xhr-polling',
- 'iframe-xhr-polling',
- 'jsonp-polling'];
- switch (typeof protocols) {
- case 'undefined': break;
- case 'string': that._protocols = [protocols]; break;
- default: that._protocols = protocols; break;
+ if (typeof protocols_whitelist === 'string') {
+ protocols_whitelist = [protocols_whitelist];
+ } else if (!utils.isArray(protocols_whitelist)) {
+ protocols_whitelist = [];
}
+ that._protocols = [];
that.protocol = null;
that.readyState = SockJS.CONNECTING;
- if (!that._options.info) {
- var ir = createInfoReceiver(that._base_url);
- ir.onfinish = function(info, rtt) {
- if (info) {
- that._applyInfo({info: info, rtt:rtt});
- that._didClose();
- } else {
- that._didClose(3000, 'Can\'t connect to server');
+ var ir = createInfoReceiver(that._base_url);
+ ir.onfinish = function(info, rtt) {
+ if (info) {
+ if (that._options.info) {
+ // Override if user supplies the option
+ info = that._options.info;
}
- };
- } else {
- that._didClose();
- }
+ that._applyInfo(info, rtt, protocols_whitelist);
+ that._didClose();
+ } else {
+ that._didClose(3000, 'Can\'t connect to server');
+ }
+ };
};
// Inheritance
SockJS.prototype = new REventTarget();
@@ -214,8 +208,11 @@ SockJS.prototype.send = function(data) {
return true;
};
-SockJS.prototype._applyInfo = function(data) {
+SockJS.prototype._applyInfo = function(info, rtt, protocols_whitelist) {
var that = this;
- that._options.info = data.info;
- that._options.rto = utils.countRTO(data.rtt);
+ that._options.info = info;
+ that._options.rtt = rtt;
+ that._options.rto = utils.countRTO(rtt);
+ var probed = utils.probeProtocols();
+ that._protocols = utils.detectProtocols(probed, protocols_whitelist, info);
};
diff --git a/lib/utils.js b/lib/utils.js
index fafb93d..a6c6b2d 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -122,6 +122,11 @@ utils.arrSkip = function(arr, obj) {
}
};
+// Via: https://gist.github.com/1133122/2121c601c5549155483f50be3da5305e83b8c5df
+utils.isArray = Array.isArray || function(value) {
+ return {}.toString.call(value).indexOf('Array') >= 0
+};
+
utils.delay = function(t, fun) {
if(typeof t === 'function') {
fun = t;
diff --git a/tests/config.js b/tests/config.js
index 94eab6d..91fe85d 100644
--- a/tests/config.js
+++ b/tests/config.js
@@ -3,7 +3,11 @@ exports.config = {
// Address of a sockjs test server.
url: 'http://localhost:8081',
disabled_transports: [],
- sockjs_opts: {devel:true, debug:true}
+ sockjs_opts: {
+ devel:true,
+ debug:true,
+ info: {websocket:true, cookie_need:false}
+ }
},
port: 8080,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git
More information about the Pkg-javascript-commits
mailing list