Compare commits

...

19 Commits

Author SHA1 Message Date
James Coglan 067df9aaf4 Bump version to 0.6.1. 2013-07-05 15:18:10 +01:00
James Coglan c6b40aefbb Older Nodes don't support chained pipe(). 2013-07-05 11:15:36 +01:00
James Coglan a68ff2c035 Start the driver asynchronously on the server to allow onopen hooks to be registered. 2013-07-04 21:55:30 +01:00
James Coglan da424b7d71 Modernize package.json. 2013-07-01 02:21:41 +01:00
James Coglan f2c08de98f Migrate to jstest. 2013-07-01 02:20:52 +01:00
James Coglan bbdbf1cb46 Correct package.json formatting. 2013-06-23 01:13:50 +01:00
James Coglan d5d4d9e009 Merge pull request #22 from cezor/master
Use singular repository to avoid warning
2013-06-22 17:12:14 -07:00
James Coglan 8a8e44b283 Support the 'ca' option to client connections, and remove the verify: false option. 2013-06-19 08:09:19 +01:00
Nick Nissen db9bbba6bc renamed repossitories keyword 2013-06-16 22:13:53 +02:00
Nick Nissen 085d8d2b43 Use singular repository to avoid warning 2013-06-15 13:54:20 +02:00
James Coglan ad572ca5e0 Turn the reflexive piping into a one-liner. 2013-05-29 02:21:53 +01:00
James Coglan b861f1a779 Woops, left a console.log in. 2013-05-12 15:04:10 +01:00
James Coglan 047f87e4cd Set status and headers on error, not just on open. 2013-05-12 14:44:57 +01:00
James Coglan d6728e115d Add support for custom handshake headers. 2013-05-12 14:39:30 +01:00
James Coglan 15aedb7ca3 Make mention of streams more prominent. 2013-05-05 09:54:47 +01:00
James Coglan 7e9149faff Remove .redcar from .npmignore. 2013-05-05 01:51:52 +01:00
James Coglan 7fc369fc82 Bump version to 0.5.0. 2013-05-05 01:47:37 +01:00
James Coglan ec4ba0eb74 Use pipe() for the Autobahn echo client. 2013-05-05 00:01:17 +01:00
James Coglan d9475f5b07 Don't end the EventSource when piping a file into it. 2013-05-04 21:37:46 +01:00
14 changed files with 123 additions and 74 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
.git
.gitignore
.npmignore
.redcar
.travis.yml
node_modules
spec
+17
View File
@@ -1,3 +1,20 @@
### 0.6.1 / 2013-07-05
* Add `ca` option to the client for specifying certificate authorities
* Start the server driver asynchronously so that `onopen` handlers can be added
### 0.6.0 / 2013-05-12
* Add support for custom headers
### 0.5.0 / 2013-05-05
* Extract the protocol handlers into the `websocket-driver` library
* Support the Node streaming API
### 0.4.4 / 2013-02-14
* Emit the `close` event if TCP is closed before CLOSE frame is acked
+30 -2
View File
@@ -52,13 +52,19 @@ server.on('upgrade', function(request, socket, body) {
console.log('close', event.code, event.reason);
ws = null;
});
}
});
server.listen(8000);
```
`WebSocket` objects are also duplex streams, so you could replace the
`ws.on('message', ...)` line with:
```js
ws.pipe(ws);
```
Note that under certain circumstances (notably a draft-76 client connecting
through an HTTP proxy), the WebSocket handshake will not be complete after you
call `new WebSocket()` because the server will not have received the entire
@@ -108,6 +114,9 @@ ws.on('close', function(event) {
});
```
The WebSocket client also lets you inspect the status and headers of the
handshake response via its `statusCode` and `headers` properties.
## Subprotocol negotiation
@@ -131,9 +140,28 @@ If the client and server agree on a protocol, both the client- and server-side
socket objects expose the selected protocol through the `ws.protocol` property.
## Initialization options
Both the server- and client-side classes allow an options object to be passed
in at initialization time, for example:
```js
var ws = new WebSocket(request, socket, body, protocols, options);
var ws = new WebSocket.Client(url, protocols, options);
```
`protocols` is an array of subprotocols as described above, or `null`.
`options` is an optional object containing any of these fields:
* `headers` - an object containing key-value pairs representing HTTP headers to
be sent during the handshake process
* `ping` - an integer that sets how often the WebSocket should send ping
frames, measured in seconds
## WebSocket API
Both server- and client-side `WebSocket` objects support the following API:
Both server- and client-side `WebSocket` objects support the following API.
* <b>`on('open', function(event) {})`</b> fires when the socket connection is
established. Event has no attributes.
+2 -8
View File
@@ -28,14 +28,8 @@ socket.onclose = function() {
} else {
socket = new WebSocket.Client(host + '/runCase?case=' + n + '&agent=' + encodeURIComponent(agent));
socket.onmessage = function(event) {
socket.send(event.data);
};
socket.onclose = function() {
runCase(n + 1);
};
socket.pipe(socket);
socket.on('close', function() { runCase(n + 1) });
}
};
+3 -1
View File
@@ -2,7 +2,9 @@ var WebSocket = require('../lib/faye/websocket'),
port = process.argv[2] || 7000,
secure = process.argv[3] === 'ssl',
scheme = secure ? 'wss' : 'ws',
ws = new WebSocket.Client(scheme + '://localhost:' + port + '/');
url = scheme + '://localhost:' + port + '/',
headers = {Origin: 'http://faye.jcoglan.com'},
ws = new WebSocket.Client(url, null, {headers: headers});
console.log('Connecting to ' + ws.url);
+1 -1
View File
@@ -35,7 +35,7 @@ var requestHandler = function(request, response) {
}, 1000);
}, 2000);
fs.createReadStream(__dirname + '/haproxy.conf').pipe(es);
fs.createReadStream(__dirname + '/haproxy.conf').pipe(es, {end: false});
es.onclose = function() {
clearInterval(loop);
+4 -4
View File
@@ -10,8 +10,6 @@ var util = require('util'),
var WebSocket = function(request, socket, body, protocols, options) {
this._stream = socket;
this._ping = options && options.ping;
this._pingId = 0;
this._driver = driver.http(request, {protocols: protocols});
var self = this;
@@ -24,13 +22,15 @@ var WebSocket = function(request, socket, body, protocols, options) {
this._stream.setNoDelay(true);
this._driver.io.write(body);
API.call(this);
API.call(this, options);
['error', 'end'].forEach(function(event) {
this._stream.on(event, function() { self._finalize('', 1006) });
}, this);
this._driver.start();
process.nextTick(function() {
self._driver.start();
});
};
util.inherits(WebSocket, API);
+10 -1
View File
@@ -3,9 +3,18 @@ var Stream = require('stream').Stream,
EventTarget = require('./api/event_target'),
Event = require('./api/event');
var API = function() {
var API = function(options) {
options = options || {};
this.readable = this.writable = true;
var headers = options.headers;
if (headers) {
for (var name in headers) this._driver.setHeader(name, headers[name]);
}
this._ping = options.ping;
this._pingId = 0;
this.readyState = API.CONNECTING;
this.bufferedAmount = 0;
this.protocol = '';
+9 -4
View File
@@ -7,16 +7,21 @@ var util = require('util'),
var Client = function(url, protocols, options) {
this.url = url;
this._uri = require('url').parse(url);
this._ping = options && options.ping;
this._pingId = 0;
this._driver = driver.client(url, {protocols: protocols});
['open', 'error'].forEach(function(event) {
this._driver.on(event, function() {
self.headers = self._driver.headers;
self.statusCode = self._driver.statusCode;
});
}, this);
var secure = (this._uri.protocol === 'wss:'),
onConnect = function() { self._driver.start() },
tlsOptions = {},
self = this;
if (options && options.verify === false) tlsOptions.rejectUnauthorized = false;
if (options && options.ca) tlsOptions.ca = options.ca;
var connection = secure
? tls.connect(this._uri.port || 443, this._uri.hostname, tlsOptions, onConnect)
@@ -28,7 +33,7 @@ var Client = function(url, protocols, options) {
if (!secure) this._stream.on('connect', onConnect);
API.call(this);
API.call(this, options);
['error', 'end'].forEach(function(event) {
this._stream.on(event, function() { self._finalize('', 1006) });
+9 -14
View File
@@ -3,25 +3,20 @@
, "homepage" : "http://github.com/faye/faye-websocket-node"
, "author" : "James Coglan <jcoglan@gmail.com> (http://jcoglan.com/)"
, "keywords" : ["websocket", "eventsource"]
, "license" : "MIT"
, "version" : "0.4.4"
, "version" : "0.6.1"
, "engines" : {"node": ">=0.4.0"}
, "main" : "./lib/faye/websocket"
, "dependencies" : {"websocket-driver": ""}
, "devDependencies" : {"jsclass": "", "pace": ""}
, "dependencies" : {"websocket-driver": ">=0.2.0"}
, "devDependencies" : {"jstest": "", "pace": ""}
, "scripts" : {"test": "node spec/runner.js"}
, "scripts" : {"test": "jstest spec/runner.js"}
, "repository" : { "type" : "git"
, "url" : "git://github.com/faye/faye-websocket-node.git"
}
, "bugs" : "http://github.com/faye/faye-websocket-node/issues"
, "licenses" : [ { "type" : "MIT"
, "url" : "http://www.opensource.org/licenses/mit-license.php"
}
]
, "repositories" : [ { "type" : "git"
, "url" : "git://github.com/faye/faye-websocket-node.git"
}
]
}
+8 -4
View File
@@ -1,6 +1,8 @@
var Client = require('../../../lib/faye/websocket/client')
var Client = require('../../../lib/faye/websocket/client'),
test = require('jstest').Test,
fs = require('fs')
JS.ENV.WebSocketSteps = JS.Test.asyncSteps({
var WebSocketSteps = test.asyncSteps({
server: function(port, secure, callback) {
this._adapter = new EchoServer()
this._adapter.listen(port, secure)
@@ -24,7 +26,9 @@ JS.ENV.WebSocketSteps = JS.Test.asyncSteps({
callback()
}
this._ws = new Client(url, protocols, {verify: false})
this._ws = new Client(url, protocols, {
ca: fs.readFileSync(__dirname + '/../../server.crt')
})
this._ws.onopen = function() { resume(true) }
this._ws.onclose = function() { resume(false) }
@@ -77,7 +81,7 @@ JS.ENV.WebSocketSteps = JS.Test.asyncSteps({
})
JS.ENV.ClientSpec = JS.Test.describe("Client", function() { with(this) {
test.describe("Client", function() { with(this) {
include(WebSocketSteps)
before(function() {
+4 -8
View File
@@ -1,12 +1,11 @@
require('jsclass')
var WebSocket = require('../lib/faye/websocket'),
fs = require('fs'),
http = require('http'),
https = require('https')
https = require('https'),
test = require('jstest').Test
JS.ENV.EchoServer = function() {}
EchoServer = function() {}
EchoServer.prototype.listen = function(port, ssl) {
var server = ssl
? https.createServer({
@@ -30,8 +29,5 @@ EchoServer.prototype.stop = function(callback, scope) {
}
JS.require('JS.Test', function() {
require('./faye/websocket/client_spec')
JS.Test.autorun()
})
require('./faye/websocket/client_spec')
+12 -13
View File
@@ -1,15 +1,14 @@
-----BEGIN CERTIFICATE-----
MIICZTCCAc4CCQDxyrJZrFA0vjANBgkqhkiG9w0BAQUFADB3MQswCQYDVQQGEwJV
SzEPMA0GA1UECBMGTG9uZG9uMQ8wDQYDVQQHEwZMb25kb24xDTALBgNVBAoTBEZh
eWUxFTATBgNVBAMTDEphbWVzIENvZ2xhbjEgMB4GCSqGSIb3DQEJARYRamNvZ2xh
bkBnbWFpbC5jb20wHhcNMTEwODMwMTIzOTM2WhcNMTIwODI5MTIzOTM2WjB3MQsw
CQYDVQQGEwJVSzEPMA0GA1UECBMGTG9uZG9uMQ8wDQYDVQQHEwZMb25kb24xDTAL
BgNVBAoTBEZheWUxFTATBgNVBAMTDEphbWVzIENvZ2xhbjEgMB4GCSqGSIb3DQEJ
ARYRamNvZ2xhbkBnbWFpbC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB
AMDjU5fAK7fvUCZIYHcGXDZD/m9bY+B/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