[Pkg-javascript-commits] [sockjs-client] 242/350: Change to options as third param on constructor. Update readme.

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:04:26 UTC 2016


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.

commit 4ee6362c8a100c4a0b09cf5648f21055d66bce35
Author: Bryce Kahle <bkahle at gmail.com>
Date:   Mon Oct 27 16:23:57 2014 -0400

    Change to options as third param on constructor. Update readme.
---
 README.md                      | 105 ++++++++---------------------------------
 lib/main.js                    |  11 ++---
 tests/lib/test-utils.js        |   2 +-
 tests/lib/transports.js        |   4 +-
 tests/support/config.js        |  15 ------
 tests/support/server.js        |  46 ------------------
 tests/support/sockjs_server.js |   2 -
 7 files changed, 28 insertions(+), 157 deletions(-)

diff --git a/README.md b/README.md
index a9fca81..2f840d1 100644
--- a/README.md
+++ b/README.md
@@ -70,14 +70,7 @@ Work in progress:
   * [SockJS-perl](https://github.com/vti/sockjs-perl)
   * [SockJS-go](https://github.com/igm/sockjs-go/)
 
-QUnit tests and smoke tests
----------------------------
-
-SockJS comes with some QUnit tests and a few smoke tests (using
-[SockJS-node](https://github.com/sockjs/sockjs-node) on the server
-side).
-
-Example
+Getting Started
 -------
 
 SockJS mimics the [WebSockets API](http://dev.w3.org/html5/websockets/),
@@ -104,6 +97,9 @@ SockJS server. Here's a simple example:
  sock.onclose = function() {
      console.log('close');
  };
+
+ sock.send('test');
+ sock.close();
 ```
 
 SockJS-client API
@@ -111,7 +107,7 @@ SockJS-client API
 
 ### SockJS class
 
-Similar to 'WebSocket' class 'SockJS' constructor takes one, or more arguments:
+Similar to the 'WebSocket' API, the 'SockJS' constructor takes one, or more arguments:
 
 ```javascript
 var sockjs = new SockJS(url, _reserved, options);
@@ -119,27 +115,15 @@ var sockjs = new SockJS(url, _reserved, options);
 
 Where `options` is a hash which can contain:
 
- *  **debug (boolean)**
-
-    Print some debugging messages using 'console.log'.
-
- *  **devel (boolean)**
-
-    Development mode. Currently, setting it disables caching of the
-    'iframe.html'.
-
  *  **server (string)**
 
     String to append to url for actual data connection. Defaults to a random 4 digit number.
 
- *  **protocols_whitelist (list of strings)**
+ *  **transports (string OR array 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']"
+    Sometimes it is useful to disable some fallback transports. This
+    option allows you to supply a list transports that may be used by
+    SockJS. By default all available transports will be used.
 
 
 Although the 'SockJS' object tries to emulate the 'WebSocket'
@@ -193,7 +177,7 @@ Sometimes you may want to serve your html from "file://" address - for
 development or if you're using PhoneGap or similar technologies. But
 due to the Cross Origin Policy files served from "file://" have no
 Origin, and that means some of SockJS transports won't work. For this
-reason the SockJS protocol table is different than usually, major
+reason the SockJS transport table is different than usually, major
 differences are:
 
 _Browser_       | _Websockets_  | _Streaming_        | _Polling_
@@ -211,7 +195,9 @@ websocket (hixie-76) | [draft-hixie-thewebsocketprotocol-76][^1]
 websocket (hybi-10)  | [draft-ietf-hybi-thewebsocketprotocol-10][^2]
 xhr-streaming        | Transport using [Cross domain XHR][^5] [streaming][^7] capability (readyState=3).
 xdr-streaming        | Transport using [XDomainRequest][^9] [streaming][^7] capability (readyState=3).
+eventsource          | [EventSource][^4].
 iframe-eventsource   | [EventSource][^4] used from an [iframe via postMessage][^3].
+htmlfile             | [HtmlFile][^8].
 iframe-htmlfile      | [HtmlFile][^8] used from an [iframe via postMessage][^3].
 xhr-polling          | Long-polling using [cross domain XHR][^5].
 xdr-polling          | Long-polling using [XDomainRequest][^9].
@@ -267,83 +253,32 @@ session stickiness, take a look at the
 Development and testing
 -----------------------
 
-SockJS-client needs [Node.js](http://nodejs.org/) for running a test
+SockJS-client needs [node.js](http://nodejs.org/) for running a test
 server and JavaScript minification. If you want to work on
-SockJS-client source code, check out the git repo and follow this
+SockJS-client source code, checkout the git repo and follow this
 steps:
 
     cd sockjs-client
     npm install
-    npm install --dev
 
 To generate JavaScript, run:
 
-    make sockjs.js
+    gulp browserify
 
 To generate minified JavaScript, run:
 
-    make sockjs.min.js
-
-(To generate both, run `make build`.)
+    gulp browserify:min
 
+Both commands output into the `build` directory.
 
 ### Testing
 
 Once you've compiled the SockJS-client you may want to check if your changes
-pass all the tests. To run the tests you need a server that can answer
-various SockJS requests. A common way is to use `SockJS-node` test
-server for that. To run it (by default it will be listening on port 8081):
-
-    cd sockjs-node
-    npm install
-    npm install --dev
-    ln -s .. node_modules/sockjs
-    make build
-    make test_server
-
-At this point you're ready to run a SockJS-client server that will
-serve your freshly compiled JavaScript and various static http and
-javascript files (by default it will run on port 8080).
-
-    cd sockjs-client
-    make test
-
-At that point you should have two web servers running: sockjs-node on
-8081 and sockjs-client on 8080. When you open the browser on
-[http://localhost:8080/](http://localhost:8080/) you should be able
-run the QUnit tests against your sockjs-node server.
-
-#### Testing Hiccups
-
-If you look at your browser console you will see warnings like:
-
-    Incompatible SockJS! Main site uses: "a", the iframe: "b".
-
-This is due to the fact that SockJS-node test server is using compiled
-JavaScript from a CDN, rather than your freshly compiled version. To fix
-that you must amend `sockjs_url` which is used by SockJS-node test
-server. Edit the [`config.js`](https://github.com/sockjs/sockjs-node/blob/master/examples/test_server/config.js) file:
-
-    vim sockjs-node/examples/test_server/config.js
-
-And replace the `sockjs_url` setting, which by default points to a CDN:
-
-    sockjs_url: 'http://cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js',
-
-to a freshly compiled SockJS, for example:
-
-    sockjs_url: 'http://localhost:8080/lib/sockjs.js',
-
-
-Also, if you want to run tests against a SockJS server not running on
-`localhost:8081` you may want to edit the
-[`tests/config.js`](https://github.com/sockjs/sockjs-client/blob/master/tests/config.js)
-file.
+pass all the tests.
 
-Additionally, if you're doing more serious development consider using
-`make serve`, which will automatically reload the server when you
-modify the source code.
+    make test-local
 
+This will start [zuul](https://github.com/defunctzombie/zuul) and a test support server. Open the browser to [http://localhost:9090/_zuul](http://localhost:9090/_zuul) and watch the tests run.
 
 Browser Quirks
 --------------
diff --git a/lib/main.js b/lib/main.js
index 02724a6..0c3ff8b 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -30,9 +30,9 @@ if (process.env.NODE_ENV !== 'production') {
 var transports;
 
 // follow constructor steps defined at http://dev.w3.org/html5/websockets/#the-websocket-interface
-function SockJS(url, protocols, transportsWhitelist) {
+function SockJS(url, protocols, options) {
   if (!(this instanceof SockJS)) {
-    return new SockJS(url, protocols, transportsWhitelist);
+    return new SockJS(url, protocols, options);
   }
   if (arguments.length < 1) {
     throw new TypeError("Failed to construct 'SockJS: 1 argument required, but only 0 present");
@@ -44,10 +44,9 @@ function SockJS(url, protocols, transportsWhitelist) {
   this.protocol = '';
 
   // non-standard extension
-  // TODO attempt to remove and provide another way
-  this._transportsWhitelist = transportsWhitelist;
-  // TODO specify via options? server routes require this
-  this._server = random.numberString(1000);
+  options = options || {};
+  this._transportsWhitelist = options.transports;
+  this._server = options.server || random.numberString(1000);
 
   // Step 1 of WS spec - parse and validate the url. Issue #8
   var parsedUrl = u.parse(url);
diff --git a/tests/lib/test-utils.js b/tests/lib/test-utils.js
index e768f7b..e74d782 100644
--- a/tests/lib/test-utils.js
+++ b/tests/lib/test-utils.js
@@ -28,7 +28,7 @@ module.exports = {
   }
 
 , newSockJs: function (path, transport) {
-    return new SockJS(this.getUrl(path), null, transport);
+    return new SockJS(this.getUrl(path), null, { transports: transport });
   }
 
 , createHook: function () {
diff --git a/tests/lib/transports.js b/tests/lib/transports.js
index ab2b7af..ca44544 100644
--- a/tests/lib/transports.js
+++ b/tests/lib/transports.js
@@ -77,7 +77,7 @@ function userClose(url, transport) {
   it('user close', function (done) {
     var test = this.runnable();
     this.timeout(10000);
-    var sjs = new SockJS(url + '/echo', null, transport);
+    var sjs = new SockJS(url + '/echo', null, { transports: transport });
     expect(sjs).to.be.ok();
     var counter = 0;
 
@@ -119,7 +119,7 @@ function serverClose(url, transport) {
   it('server close', function (done) {
     var test = this.runnable();
     this.timeout(10000);
-    var sjs = new SockJS(url + '/close', null, transport);
+    var sjs = new SockJS(url + '/close', null, { transports: transport });
     expect(sjs).to.be.ok();
     var i = 0;
     sjs.onopen = function() {
diff --git a/tests/support/config.js b/tests/support/config.js
deleted file mode 100644
index 00fb41e..0000000
--- a/tests/support/config.js
+++ /dev/null
@@ -1,15 +0,0 @@
-exports.config = {
-    client_opts: {
-        // Address of a sockjs test server.
-        url: 'http://localhost:8081',
-        sockjs_opts: {
-            devel: true,
-            debug: true,
-            // websocket:false
-            info: {cookie_needed:false}
-        }
-    },
-
-    port: 8080,
-    host: '0.0.0.0'
-};
diff --git a/tests/support/server.js b/tests/support/server.js
deleted file mode 100644
index e0d5edb..0000000
--- a/tests/support/server.js
+++ /dev/null
@@ -1,46 +0,0 @@
-'use strict';
-
-var http = require('http');
-var node_static = require('node-static');
-var url = require('url');
-
-var config = require('./config').config;
-
-var static_directory = new node_static.Server(__dirname + '/html', { cache: 0 });
-
-var server = http.createServer();
-server.addListener('request', function(req, res) {
-    if ( /\/slow-script.js/.test(req.url) ) {
-        res.setHeader('content-type', 'application/javascript');
-        res.writeHead(200);
-        setTimeout(function() {
-            res.end('var a = 1;\n');
-        }, 500);
-    } else if ( /\/streaming.txt/.test(req.url) ) {
-        res.setHeader('content-type', 'text/plain');
-        res.setHeader('Access-Control-Allow-Origin', '*');
-
-        res.writeHead(200);
-        res.write(new Array(2049).join('a') + '\n');
-        setTimeout(function() {
-            res.end('b\n');
-        }, 250);
-    } else if ( /\/simple.txt/.test(req.url) ) {
-        res.setHeader('content-type', 'text/plain');
-        res.setHeader('Access-Control-Allow-Origin', '*');
-        res.writeHead(200);
-        res.end(new Array(2049).join('a') + '\nb\n');
-    } else if (req.url === '/config.js') {
-        var parsedOrigin = url.parse(req.headers.referer || 'http://localhost');
-        config.client_opts.url = parsedOrigin.protocol + '//' + parsedOrigin.hostname + ':8081';
-        res.setHeader('content-type', 'application/javascript');
-        res.writeHead(200);
-        res.end('var client_opts = ' +
-                JSON.stringify(config.client_opts) + ';');
-    } else {
-        static_directory.serve(req, res);
-    }
-});
-
-console.log(" [*] Listening on", config.host + ':' + config.port);
-server.listen(config.port, config.host);
diff --git a/tests/support/sockjs_server.js b/tests/support/sockjs_server.js
index 77fb992..edfc025 100644
--- a/tests/support/sockjs_server.js
+++ b/tests/support/sockjs_server.js
@@ -13,8 +13,6 @@ var clientOptions = {
   // Address of a sockjs test server.
   url: 'http://localhost:' + port,
   sockjs_opts: {
-      devel: true,
-      debug: true,
       // websocket:false
       info: {cookie_needed:false}
   }

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