Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dc392490a8 | |||
| 0feee7974c | |||
| 91d8e1ad41 | |||
| c27fee0680 | |||
| 061494bc2c | |||
| 958d3a458f | |||
| 2d945cff5d | |||
| d3340cdd63 | |||
| 0d15d7a3ec | |||
| cdc7f0891b | |||
| f8c5b86e10 | |||
| 53db3d6c25 | |||
| dcb3375dda | |||
| 854c0a9658 | |||
| d753d09372 | |||
| febde17f0e | |||
| c52271c308 | |||
| 8460dd9f03 | |||
| 66fc108591 | |||
| 58491dea2b | |||
| cd220deb74 | |||
| 6c1689a73d | |||
| 29b94290e9 | |||
| 63e16f6341 |
+6
-1
@@ -1,7 +1,12 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "iojs"
|
||||
- "iojs-1"
|
||||
- "iojs-2"
|
||||
- "iojs-3"
|
||||
- "4"
|
||||
- "5"
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
### 0.11.0 / 2016-02-24
|
||||
|
||||
* Introduce a `net` option to the `Client` class for setting things like, say, `servername`
|
||||
|
||||
### 0.10.0 / 2015-07-08
|
||||
|
||||
* Add the standard `code` and `reason` parameters to the `close` method
|
||||
|
||||
### 0.9.4 / 2015-03-08
|
||||
|
||||
* Don't send input to the driver before `start()` is called
|
||||
|
||||
### 0.9.3 / 2015-02-19
|
||||
|
||||
* Make sure the TCP socket is not left open when closing the connection
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# Code of Conduct
|
||||
|
||||
All projects under the [Faye](https://github.com/faye) umbrella are covered by
|
||||
the [Code of Conduct](https://github.com/faye/code-of-conduct).
|
||||
@@ -9,7 +9,7 @@ This is a general-purpose WebSocket implementation extracted from the
|
||||
[Faye](http://faye.jcoglan.com) project. It provides classes for easily building
|
||||
WebSocket servers and clients in Node. It does not provide a server itself, but
|
||||
rather makes it easy to handle WebSocket connections within an existing
|
||||
[Node](http://nodejs.org/) application. It does not provide any abstraction
|
||||
[Node](https://nodejs.org/) application. It does not provide any abstraction
|
||||
other than the standard [WebSocket API](http://dev.w3.org/html5/websockets/).
|
||||
|
||||
It also provides an abstraction for handling
|
||||
@@ -77,8 +77,9 @@ If you need to detect when the WebSocket handshake is complete, you can use the
|
||||
If the connection's protocol version supports it, you can call `ws.ping()` to
|
||||
send a ping message and wait for the client's response. This method takes a
|
||||
message string, and an optional callback that fires when a matching pong message
|
||||
is received. It returns `true` iff a ping message was sent. If the client does
|
||||
not support ping/pong, this method sends no data and returns `false`.
|
||||
is received. It returns `true` if and only if a ping message was sent. If the
|
||||
client does not support ping/pong, this method sends no data and returns
|
||||
`false`.
|
||||
|
||||
```js
|
||||
ws.ping('Mic check, one, two', function() {
|
||||
@@ -120,7 +121,7 @@ including any authorization information, custom headers and TLS config you
|
||||
require. Only the `origin` setting is required.
|
||||
|
||||
```js
|
||||
var ws = new WebSocket.Client('ws://www.example.com/', null, {
|
||||
var ws = new WebSocket.Client('ws://www.example.com/', [], {
|
||||
proxy: {
|
||||
origin: 'http://username:password@proxy.example.com',
|
||||
headers: {'User-Agent': 'node'},
|
||||
@@ -129,8 +130,8 @@ var ws = new WebSocket.Client('ws://www.example.com/', null, {
|
||||
});
|
||||
```
|
||||
|
||||
The `tls` value is a Node 'TLS options' object that will be passed to
|
||||
[`tls.connect()`](http://nodejs.org/api/tls.html#tls_tls_connect_options_callback).
|
||||
The `tls` value is an object that will be passed to
|
||||
[`tls.connect()`](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback).
|
||||
|
||||
|
||||
## Subprotocol negotiation
|
||||
@@ -167,7 +168,7 @@ array of extensions to the `:extensions` option. For example, to add
|
||||
```js
|
||||
var deflate = require('permessage-deflate');
|
||||
|
||||
var ws = new WebSocket(request, socket, body, null, {extensions: [deflate]});
|
||||
var ws = new WebSocket(request, socket, body, [], {extensions: [deflate]});
|
||||
```
|
||||
|
||||
|
||||
@@ -197,9 +198,12 @@ var ws = new WebSocket.Client(url, protocols, options);
|
||||
The client accepts some additional options:
|
||||
|
||||
* `proxy` - settings for a proxy as described above
|
||||
* `tls` - a Node 'TLS options' object containing TLS settings for the origin
|
||||
server, this will be passed to
|
||||
[`tls.connect()`](http://nodejs.org/api/tls.html#tls_tls_connect_options_callback)
|
||||
* `net` - an object containing settings for the origin server that will be
|
||||
passed to
|
||||
[`net.connect()`](https://nodejs.org/api/net.html#net_socket_connect_options_connectlistener)
|
||||
* `tls` - an object containing TLS settings for the origin server, this will be
|
||||
passed to
|
||||
[`tls.connect()`](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback)
|
||||
* `ca` - (legacy) a shorthand for passing `{tls: {ca: value}}`
|
||||
|
||||
|
||||
@@ -221,7 +225,7 @@ Both server- and client-side `WebSocket` objects support the following API.
|
||||
that closed the connection.
|
||||
* <b>`send(message)`</b> accepts either a `String` or a `Buffer` and sends a
|
||||
text or binary message over the connection to the other peer.
|
||||
* <b>`ping(message = '', function() {})`</b> sends a ping frame with an optional
|
||||
* <b>`ping(message, function() {})`</b> sends a ping frame with an optional
|
||||
message and fires the callback when a matching pong is received.
|
||||
* <b>`close(code, reason)`</b> closes the connection, sending the given status
|
||||
code and reason text, both of which are optional.
|
||||
@@ -315,7 +319,7 @@ some data over the wire to keep the connection alive.
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2010-2015 James Coglan
|
||||
Copyright (c) 2010-2016 James Coglan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the 'Software'), to deal in
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var WebSocket = require('../lib/faye/websocket'),
|
||||
var WebSocket = require('..').Client,
|
||||
deflate = require('permessage-deflate'),
|
||||
pace = require('pace');
|
||||
|
||||
@@ -7,7 +7,7 @@ var host = 'ws://localhost:9001',
|
||||
cases = 0,
|
||||
options = {extensions: [deflate]};
|
||||
|
||||
var socket = new WebSocket.Client(host + '/getCaseCount'),
|
||||
var socket = new WebSocket(host + '/getCaseCount'),
|
||||
url, progress;
|
||||
|
||||
socket.onmessage = function(event) {
|
||||
@@ -19,13 +19,13 @@ socket.onmessage = function(event) {
|
||||
var runCase = function(n) {
|
||||
if (n > cases) {
|
||||
url = host + '/updateReports?agent=' + agent;
|
||||
socket = new WebSocket.Client(url);
|
||||
socket = new WebSocket(url);
|
||||
socket.onclose = process.exit;
|
||||
return;
|
||||
}
|
||||
|
||||
url = host + '/runCase?case=' + n + '&agent=' + agent;
|
||||
socket = new WebSocket.Client(url, null, options);
|
||||
socket = new WebSocket(url, [], options);
|
||||
socket.pipe(socket);
|
||||
|
||||
socket.on('close', function() {
|
||||
|
||||
+14
-7
@@ -1,11 +1,18 @@
|
||||
var WebSocket = require('../lib/faye/websocket'),
|
||||
fs = require('fs');
|
||||
var WebSocket = require('..').Client,
|
||||
deflate = require('permessage-deflate'),
|
||||
fs = require('fs');
|
||||
|
||||
var url = process.argv[2],
|
||||
headers = {Origin: 'http://faye.jcoglan.com'},
|
||||
ca = fs.readFileSync(__dirname + '/../spec/server.crt'),
|
||||
proxy = {origin: process.argv[3], headers: {'User-Agent': 'Echo'}, tls: {ca: ca}},
|
||||
ws = new WebSocket.Client(url, null, {headers: headers, proxy: proxy, tls: {ca: ca}});
|
||||
var url = process.argv[2],
|
||||
proxy = process.argv[3],
|
||||
ca = fs.readFileSync(__dirname + '/../spec/server.crt'),
|
||||
tls = {ca: ca};
|
||||
|
||||
var ws = new WebSocket(url, [], {
|
||||
proxy: {origin: proxy, headers: {'User-Agent': 'Echo'}, tls: tls},
|
||||
tls: tls,
|
||||
headers: {Origin: 'http://faye.jcoglan.com'},
|
||||
extensions: [deflate]
|
||||
});
|
||||
|
||||
ws.onopen = function() {
|
||||
console.log('[open]', ws.headers);
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
var WebSocket = require('../lib/faye/websocket'),
|
||||
var WebSocket = require('..'),
|
||||
deflate = require('permessage-deflate'),
|
||||
fs = require('fs'),
|
||||
http = require('http'),
|
||||
|
||||
@@ -21,11 +21,11 @@ var WebSocket = function(request, socket, body, protocols, options) {
|
||||
var catchup = function() { self._stream.removeListener('data', catchup) };
|
||||
this._stream.on('data', catchup);
|
||||
|
||||
this._driver.io.write(body);
|
||||
API.call(this, options);
|
||||
|
||||
process.nextTick(function() {
|
||||
self._driver.start();
|
||||
self._driver.io.write(body);
|
||||
});
|
||||
};
|
||||
util.inherits(WebSocket, API);
|
||||
|
||||
@@ -92,9 +92,17 @@ var instance = {
|
||||
return this._driver.ping(message, callback);
|
||||
},
|
||||
|
||||
close: function() {
|
||||
close: function(code, reason) {
|
||||
if (code === undefined) code = 1000;
|
||||
if (reason === undefined) reason = '';
|
||||
|
||||
if (code !== 1000 && (code < 3000 || code > 4999))
|
||||
throw new Error("Failed to execute 'close' on WebSocket: " +
|
||||
"The code must be either 1000, or between 3000 and 4999. " +
|
||||
code + " is neither.");
|
||||
|
||||
if (this.readyState !== API.CLOSED) this.readyState = API.CLOSING;
|
||||
this._driver.close();
|
||||
this._driver.close(reason, code);
|
||||
},
|
||||
|
||||
_configureStream: function() {
|
||||
@@ -145,12 +153,12 @@ var instance = {
|
||||
_beginClose: function(reason, code) {
|
||||
if (this.readyState === API.CLOSED) return;
|
||||
this.readyState = API.CLOSING;
|
||||
this._closeParams = [reason, code];
|
||||
|
||||
if (this._stream) {
|
||||
this._stream.end();
|
||||
if (!this._stream.readable) this._finalizeClose();
|
||||
}
|
||||
this._closeParams = [reason, code];
|
||||
},
|
||||
|
||||
_finalizeClose: function() {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
var util = require('util'),
|
||||
net = require('net'),
|
||||
tls = require('tls'),
|
||||
crypto = require('crypto'),
|
||||
url = require('url'),
|
||||
driver = require('websocket-driver'),
|
||||
API = require('./api'),
|
||||
@@ -23,20 +22,25 @@ var Client = function(_url, protocols, options) {
|
||||
});
|
||||
}, this);
|
||||
|
||||
var proxy = options.proxy || {},
|
||||
endpoint = url.parse(proxy.origin || this.url),
|
||||
port = endpoint.port || DEFAULT_PORTS[endpoint.protocol],
|
||||
secure = SECURE_PROTOCOLS.indexOf(endpoint.protocol) >= 0,
|
||||
onConnect = function() { self._onConnect() },
|
||||
originTLS = options.tls || {},
|
||||
socketTLS = proxy.origin ? (proxy.tls || {}) : originTLS,
|
||||
self = this;
|
||||
var proxy = options.proxy || {},
|
||||
endpoint = url.parse(proxy.origin || this.url),
|
||||
port = endpoint.port || DEFAULT_PORTS[endpoint.protocol],
|
||||
secure = SECURE_PROTOCOLS.indexOf(endpoint.protocol) >= 0,
|
||||
onConnect = function() { self._onConnect() },
|
||||
netOptions = options.net || {},
|
||||
originTLS = options.tls || {},
|
||||
socketTLS = proxy.origin ? (proxy.tls || {}) : originTLS,
|
||||
self = this;
|
||||
|
||||
netOptions.host = socketTLS.host = endpoint.hostname;
|
||||
netOptions.port = socketTLS.port = port;
|
||||
|
||||
originTLS.ca = originTLS.ca || options.ca;
|
||||
socketTLS.servername = socketTLS.servername || endpoint.hostname;
|
||||
|
||||
this._stream = secure
|
||||
? tls.connect(port, endpoint.hostname, socketTLS, onConnect)
|
||||
: net.connect(port, endpoint.hostname, onConnect);
|
||||
? tls.connect(socketTLS, onConnect)
|
||||
: net.connect(netOptions, onConnect);
|
||||
|
||||
if (proxy.origin) this._configureProxy(proxy, originTLS);
|
||||
|
||||
|
||||
+4
-4
@@ -1,12 +1,12 @@
|
||||
{ "name" : "faye-websocket"
|
||||
, "description" : "Standards-compliant WebSocket server and client"
|
||||
, "homepage" : "http://github.com/faye/faye-websocket-node"
|
||||
, "homepage" : "https://github.com/faye/faye-websocket-node"
|
||||
, "author" : "James Coglan <jcoglan@gmail.com> (http://jcoglan.com/)"
|
||||
, "keywords" : ["websocket", "eventsource"]
|
||||
, "license" : "MIT"
|
||||
|
||||
, "version" : "0.9.3"
|
||||
, "engines" : {"node": ">=0.4.0"}
|
||||
, "version" : "0.11.0"
|
||||
, "engines" : {"node": ">=0.8.0"}
|
||||
, "main" : "./lib/faye/websocket"
|
||||
, "dependencies" : {"websocket-driver": ">=0.5.1"}
|
||||
, "devDependencies" : {"jstest": "", "pace": "", "permessage-deflate": ""}
|
||||
@@ -17,5 +17,5 @@
|
||||
, "url" : "git://github.com/faye/faye-websocket-node.git"
|
||||
}
|
||||
|
||||
, "bugs" : "http://github.com/faye/faye-websocket-node/issues"
|
||||
, "bugs" : "https://github.com/faye/faye-websocket-node/issues"
|
||||
}
|
||||
|
||||
@@ -73,8 +73,11 @@ var WebSocketSteps = test.asyncSteps({
|
||||
this._ws.close()
|
||||
},
|
||||
|
||||
check_open: function(callback) {
|
||||
check_open: function(status, headers, callback) {
|
||||
this.assert( this._open )
|
||||
this.assertEqual( status, this._ws.statusCode )
|
||||
for (var name in headers)
|
||||
this.assertEqual( headers[name], this._ws.headers[name.toLowerCase()] )
|
||||
callback()
|
||||
},
|
||||
|
||||
@@ -154,7 +157,7 @@ test.describe("Client", function() { with(this) {
|
||||
sharedBehavior("socket client", function() { with(this) {
|
||||
it("can open a connection", function() { with(this) {
|
||||
open_socket(socket_url, protocols)
|
||||
check_open()
|
||||
check_open(101, {"Upgrade": "websocket"})
|
||||
check_protocol("echo")
|
||||
}})
|
||||
|
||||
|
||||
+11
-12
@@ -1,14 +1,13 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICIzCCAYwCCQDZaunNGmqaHjANBgkqhkiG9w0BAQUFADBWMQswCQYDVQQGEwJH
|
||||
QjETMBEGA1UECBMKU29tZS1TdGF0ZTEPMA0GA1UEBxMGTG9uZG9uMQ0wCwYDVQQK
|
||||
EwRGYXllMRIwEAYDVQQDEwlsb2NhbGhvc3QwHhcNMTQwNjIxMDkzNjAyWhcNMTUw
|
||||
NjIxMDkzNjAyWjBWMQswCQYDVQQGEwJHQjETMBEGA1UECBMKU29tZS1TdGF0ZTEP
|
||||
MA0GA1UEBxMGTG9uZG9uMQ0wCwYDVQQKEwRGYXllMRIwEAYDVQQDEwls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07fZpTpX9nuF8tKhZ2jSNL5DntAqm
|
||||
M48g9rKd4wKp6IsPa66bkp/6u9k6hL2EhSWQTI7ii5Ap6u649XMB/lTEY4ZK/OGn
|
||||
dnWXbPWznhgi30ROUzxUCev+yRVdlgLBJFerXzk=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
+13
-13
@@ -1,15 +1,15 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICXQIBAAKBgQDXOuP0udRdjlcNSBmapePN0rFH+0Irh8hwmMXhwfAnkyl8mh+Y
|
||||
dyE5pqo80+TFoE2Ll39/V0X9laonC1qrNMSAHESgRNVaLizNLGzczL9cjRu4ptGz
|
||||
MsFzZTpTplIbY2GbxMeSNdFIia1cSKRJzYgrmXYArgfeOJf5UK53ZGqlrQIDAQAB
|
||||
AoGBAK8U+NrbUCXK5IWpYSqsR+PmwNANVIaUrjjqDg7X9MQ8skLqHUmpnx2GtnVE
|
||||
6ZTaEjq7wruUAxuF5CRe2CLtieouaLvF/gcAsff2Q4kL8taDrM54ECC69JFfijE4
|
||||
jJfEkoJRi1B0nq2QxJke3Sm3vrW2zLDqAZ4EUIh3uxXIYgcBAkEA+imv190S+bCM
|
||||
3H/3L5LHeTRwL58HWcYYjx+/K85yaCqf4wrwyYQ1jRho76uqkjq1mvL65nOniIxd
|
||||
NRnLTiQ+jwJBANxAiY4ww16fUkBGBh2np0FfDUhWgk5G5aZWHsK+5SJZXvlV0kmn
|
||||
kf2R+8hEzAAaOh3Y4d4UBXzOZCKh0nxYdgMCQQCNsQ7oNU+KHXWrbs+TIo/ZFtp0
|
||||
Hp8LOiiu6Exfg49JcNsevhOkED5ErI7DMXhrWtWB7h4uaVN7BAXHDdUZbW4BAkAp
|
||||
Yys1/+3GaxPOphniGq3wN8dML41e3i2rOwWevLZb5QVWvwy78HQbfQIeGOdooYUI
|
||||
NMgErih10ma4p0XhPdI3AkBFp830jNItVGZtVvNRmtx2AR370qMs+AwFTK76mcMW
|
||||
xysAGnAUv7h6Qx+M6b3He8OcWVMNqMiv8yI/o2PnsvUS
|
||||
MIICXQIBAAKBgQDPK24W0QyZVbF3Scz+EJkBU12QEnfT/65MSzNSdtDeuGEjb2ir
|
||||
F+E/5av3XrczMXz/NkiqBzdyLUyMiPw4kkVkUFX0NH/Zt8RD6W8r8h1Yss0Wssvs
|
||||
TxqKgtu8k3ftNyrTIvMPwaylKg8BTscJhTy8bDrAb3FM7cyrf+Bj2qN4bQIDAQAB
|
||||
AoGBAJym5nPyV2iK18qvz4Y93rSV6SXMETgJGi8unfw5Q+9l1G4LDEZzpCvA66v9
|
||||
vuHDBhWlYoTPOCnp/vw1iSLt1/GJw62Hou8ewWJ/lrhiGHONwSWdWFV+G0juSXp/
|
||||
yNos8ZvqOn8l67uremEIqsNqOZ3hJXKauEp4i1OF7W4y+Q6xAkEA891VfTKtL1yQ
|
||||
5uLu+8drzXc9NVLnG0VVKZGg5sCfqhmijklcG7kdfNW66ujsVs3MlROsfPmC1k6B
|
||||
OQN7i3h0lwJBANl6oMPnXxEnSOCSG1Ff6wEKnfdl3wuI9w+XTYd2jdi3oTffEYU0
|
||||
l1KvtyfcpX5K254FhY3c86RI2l1XAeN5R5sCQBsqzCxPafW9xTLDk0YfWEYig4Ie
|
||||
QzrJhYxE+fza9q6XfoGFcKpx+/P9R36GBlZBRQpSj8O4dDf1tPWqCqhl+e8CQCTp
|
||||
/6fA+g37UQ9tPV3OniELIE0B6Z4XnXf0AqDfqqwCX0cQgfTOPHE4iiol9aE+K5Di
|
||||
9wxhWKmmBAqb3iIyT8kCQQCtZiSOAu75DZdufUDUoAXCXPOwxga3Km+FoloRkp5e
|
||||
O2fJKycb9tnoeMvXqLHBV7FjKH+9fPfOnKpPSETWho+8
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
Reference in New Issue
Block a user