[Pkg-javascript-commits] [sockjs-client] 322/434: API change - handle `protocols_whitelist` option instead of second parameter to the construcotr.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:22 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 33fcc8991793b06a38dc941b28a6c97c26781272
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Wed Jan 18 13:01:17 2012 +0000

    API change - handle `protocols_whitelist` option instead of second parameter to the construcotr.
---
 README.md                           | 19 ++++++++++++-------
 lib/sockjs.js                       | 30 ++++++++++++++++++++++--------
 tests/html/example-cursors.html     |  5 ++++-
 tests/html/smoke-reconnect.html     |  5 ++++-
 tests/html/smoke-throughput.html    |  5 ++++-
 tests/html/src/endtoendtests.coffee |  3 ++-
 tests/html/src/tests.coffee         |  4 +++-
 tests/html/src/unittests.coffee     |  3 ++-
 8 files changed, 53 insertions(+), 21 deletions(-)

diff --git a/README.md b/README.md
index e89b687..8a3b1d0 100644
--- a/README.md
+++ b/README.md
@@ -107,24 +107,29 @@ SockJS-client API
 Similar to 'WebSocket' class 'SockJS' constructor takes one, or more arguments:
 
 ```javascript
-var sockjs = new SockJS(url, protocols, options);
+var sockjs = new SockJS(url, _reserved, options);
 ```
 
 Where `options` is a hash which can contain:
 
  *  **debug (boolean)**
 
-    Print more debugging messages using 'console.log'.
+    Print some debugging messages using 'console.log'.
 
  *  **devel (boolean)**
 
-    Development mode. Currently settint it affects only caching of 'iframe.html'.
+    Development mode. Currently setting it disables caching of the
+    'iframe.html'.
 
- *  **cookie (boolean)**
+ *  **protocols_whitelist (list of strings)**
+
+    Sometimes it is useful to disable some fallback protocols. This
+    option allows you to supply a list protocols that may be used by
+    SockJS. By default all available protocols will be used, which is
+    equivalent to supplying: "['websocket', 'xdr-streaming', 'xhr-streaming',
+    'iframe-eventsource', 'iframe-htmlfile', 'xdr-polling', 'xhr-polling',
+    'iframe-xhr-polling', 'jsonp-polling']"
 
-    Disables transports which doesn't support cookies (ie: XDR on
-    IE). Usefull for load balancing based on sticky sessions provided
-    by JSESSIONID cookie.
 
 Although the 'SockJS' object tries to emulate the 'WebSocket'
 behaviour, it's impossible to support all features. One of the
diff --git a/lib/sockjs.js b/lib/sockjs.js
index 3d7b2f2..6173327 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -1,16 +1,30 @@
-var SockJS = function(url, protocols_whitelist, options) {
-    var that = this;
-    that._options = {devel: false, debug: false, info: undefined, rtt: undefined};
+var SockJS = function(url, dep_protocols_whitelist, options) {
+    var that = this, protocols_whitelist;
+    that._options = {devel: false, debug: false, protocols_whitelist: [],
+                     info: undefined, rtt: undefined};
     if (options) {
         utils.objectExtend(that._options, options);
     }
     that._base_url = utils.amendUrl(url);
     that._server = that._options.server || utils.random_number_string(1000);
-    if (typeof protocols_whitelist === 'string' &&
-        protocols_whitelist.length > 0) {
-        protocols_whitelist = [protocols_whitelist];
-    } else if (!utils.isArray(protocols_whitelist)) {
-        protocols_whitelist = null;
+    if (that._options.protocols_whitelist &&
+        that._options.protocols_whitelist.length) {
+        protocols_whitelist = that._options.protocols_whitelist;
+    } else {
+        // Deprecated API
+        if (typeof dep_protocols_whitelist === 'string' &&
+            dep_protocols_whitelist.length > 0) {
+            protocols_whitelist = [dep_protocols_whitelist];
+        } else if (utils.isArray(dep_protocols_whitelist)) {
+            protocols_whitelist = dep_protocols_whitelist
+        } else {
+            protocols_whitelist = null;
+        }
+        if (protocols_whitelist) {
+            that._debug('Deprecated API: Use "protocols_whitelist" option ' +
+                        'instead of supplying protocol list as a second ' +
+                        'parameter to SockJS constructor.');
+        }
     }
     that._protocols = [];
     that.protocol = null;
diff --git a/tests/html/example-cursors.html b/tests/html/example-cursors.html
index b5a08fc..9df37ef 100644
--- a/tests/html/example-cursors.html
+++ b/tests/html/example-cursors.html
@@ -73,7 +73,10 @@
                       'jsonp-polling'];
         }
         log('[connecting] ' + protocol);
-        sjs = new SockJS(client_opts.url + '/broadcast', protocol, client_opts.sockjs_opts);
+        options = jQuery.extend({}, client_opts.sockjs_opts)
+        options.protocols_whitelist = typeof protocol === 'string' ?
+                                                        [protocol] : protocol;
+        sjs = new SockJS(client_opts.url + '/broadcast', null, options);
         sjs.onopen = onopen
         sjs.onclose = onclose;
         sjs.onmessage = xonmessage;
diff --git a/tests/html/smoke-reconnect.html b/tests/html/smoke-reconnect.html
index 0765a34..ae07cbf 100644
--- a/tests/html/smoke-reconnect.html
+++ b/tests/html/smoke-reconnect.html
@@ -57,7 +57,10 @@
     function onclose(e) {
         if (started && e.code === 1000) {
             t0 = (new Date()).getTime();
-            sjs = new SockJS(client_opts.url + '/echo', protocol, client_opts.sockjs_opts);
+            options = jQuery.extend({}, client_opts.sockjs_opts)
+            options.protocols_whitelist = typeof protocol === 'string' ?
+                                                            [protocol] : protocol;
+            sjs = new SockJS(client_opts.url + '/echo', null, options);
             sjs.onopen = onopen
             sjs.onclose = onclose;
         } else {
diff --git a/tests/html/smoke-throughput.html b/tests/html/smoke-throughput.html
index 4c2b482..217238d 100644
--- a/tests/html/smoke-throughput.html
+++ b/tests/html/smoke-throughput.html
@@ -71,7 +71,10 @@
         $('#disconnect').each(function(_,e){e.disabled='';});
         var protocol = $('#transport').val() || undefined;
         log('[connecting] ' + protocol);
-        sjs = new SockJS(client_opts.url + '/echo', protocol, client_opts.sockjs_opts);
+        options = jQuery.extend({}, client_opts.sockjs_opts)
+        options.protocols_whitelist = typeof protocol === 'string' ?
+                                                        [protocol] : protocol;
+        sjs = new SockJS(client_opts.url + '/echo', null, options);
         sjs.onopen = onopen
         sjs.onclose = onclose;
         sjs.onmessage = xonmessage;
diff --git a/tests/html/src/endtoendtests.coffee b/tests/html/src/endtoendtests.coffee
index 84cdd52..84b40bd 100644
--- a/tests/html/src/endtoendtests.coffee
+++ b/tests/html/src/endtoendtests.coffee
@@ -13,7 +13,8 @@ factory_body_check = (protocol) ->
             code = """
             hook.test_body(!!document.body, typeof document.body);
 
-            var sock = new SockJS('""" + url + """', '""" + protocol + """');
+            var sock = new SockJS('""" + url + """', null,
+                                  {protocols_whitelist:['""" + protocol + """']});
             sock.onopen = function() {
                 var m = hook.onopen();
                 sock.send(m);
diff --git a/tests/html/src/tests.coffee b/tests/html/src/tests.coffee
index 75dafdd..ed9846d 100644
--- a/tests/html/src/tests.coffee
+++ b/tests/html/src/tests.coffee
@@ -10,7 +10,9 @@ protocols = ['websocket',
 
 newSockJS = (path, protocol) ->
     url = if /^http/.test(path) then path else client_opts.url + path
-    return new SockJS(url, [protocol], client_opts.sockjs_opts)
+    options = jQuery.extend({}, client_opts.sockjs_opts)
+    options.protocols_whitelist = [protocol]
+    return new SockJS(url, null, options)
 
 echo_factory_factory = (protocol, messages) ->
     return ->
diff --git a/tests/html/src/unittests.coffee b/tests/html/src/unittests.coffee
index 1cdd281..1ed2b06 100644
--- a/tests/html/src/unittests.coffee
+++ b/tests/html/src/unittests.coffee
@@ -148,7 +148,8 @@ test 'detectProtocols', ->
 
 test "EventEmitter", ->
     expect(4)
-    r = new SockJS('//wrongdomainthatdoesntresolveatall/abc', [])
+    r = new SockJS('//wrongdomainthatdoesntresolveatall/abc', null,
+                   {protocols_whitelist: []})
     r.addEventListener 'message', -> ok(true)
     r.onmessage = -> fail(true)
     bluff = -> fail(true)

-- 
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