Compare commits
41 Commits
extract_parser
...
0.7.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 4db640660d | |||
| 4353dd8c36 | |||
| 308f930160 | |||
| 5d7e9ef9a3 | |||
| 07217fe317 | |||
| 29ef6b04a5 | |||
| 1030d38093 | |||
| fa7dcf365c | |||
| 018ef183bf | |||
| b545e8b80f | |||
| 07f5ef6f95 | |||
| 052120b3d5 | |||
| f97fd88e02 | |||
| a8481f8cdd | |||
| d0c9689747 | |||
| e668e64271 | |||
| f0b97a8005 | |||
| e3cc891187 | |||
| d1f2c2172d | |||
| 0eb7d7173d | |||
| 426e72786b | |||
| b126e31b81 | |||
| 067df9aaf4 | |||
| c6b40aefbb | |||
| a68ff2c035 | |||
| da424b7d71 | |||
| f2c08de98f | |||
| bbdbf1cb46 | |||
| d5d4d9e009 | |||
| 8a8e44b283 | |||
| db9bbba6bc | |||
| 085d8d2b43 | |||
| ad572ca5e0 | |||
| b861f1a779 | |||
| 047f87e4cd | |||
| d6728e115d | |||
| 15aedb7ca3 | |||
| 7e9149faff | |||
| 7fc369fc82 | |||
| ec4ba0eb74 | |||
| d9475f5b07 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
.git
|
||||
.gitignore
|
||||
.npmignore
|
||||
.redcar
|
||||
.travis.yml
|
||||
node_modules
|
||||
spec
|
||||
|
||||
@@ -6,3 +6,5 @@ node_js:
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
|
||||
before_install:
|
||||
- '[ "${TRAVIS_NODE_VERSION}" = "0.6" ] && npm conf set strict-ssl false || true'
|
||||
|
||||
+38
-1
@@ -1,3 +1,41 @@
|
||||
### 0.7.3 / 2014-10-04
|
||||
|
||||
* Allow sockets to be closed when they are in any state other than `CLOSED`
|
||||
|
||||
|
||||
### 0.7.2 / 2013-12-29
|
||||
|
||||
* Make sure the `close` event is emitted by clients on Node v0.10
|
||||
|
||||
|
||||
### 0.7.1 / 2013-12-03
|
||||
|
||||
* Support the `maxLength` websocket-driver option
|
||||
* Make the client emit `error` events on network errors
|
||||
|
||||
|
||||
### 0.7.0 / 2013-09-09
|
||||
|
||||
* Allow the server to send custom headers with EventSource responses
|
||||
|
||||
|
||||
### 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
|
||||
@@ -59,4 +97,3 @@
|
||||
### 0.1.0 / 2011-11-27
|
||||
|
||||
* Initial release, based on WebSocket components from Faye
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# faye-websocket
|
||||
|
||||
* Travis CI build: [](http://travis-ci.org/faye/faye-websocket-node)
|
||||
status](https://secure.travis-ci.org/faye/faye-websocket-node.svg)](http://travis-ci.org/faye/faye-websocket-node)
|
||||
* Autobahn tests: [server](http://faye.jcoglan.com/autobahn/servers/),
|
||||
[client](http://faye.jcoglan.com/autobahn/clients/)
|
||||
|
||||
@@ -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,30 @@ 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
|
||||
* `maxLength` - the maximum allowed size of incoming message frames, in bytes.
|
||||
The default value is `2^26 - 1`, or 1 byte short of 64 MiB.
|
||||
* `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.
|
||||
@@ -215,17 +245,23 @@ The `EventSource` object exposes the following properties:
|
||||
When you initialize an EventSource with ` new EventSource()`, you can pass
|
||||
configuration options after the `response` parameter. Available options are:
|
||||
|
||||
* <b>`headers`</b> is an object containing custom headers to be set on the
|
||||
EventSource response.
|
||||
* <b>`retry`</b> is a number that tells the client how long (in seconds) it
|
||||
should wait after a dropped connection before attempting to reconnect.
|
||||
* <b>`ping`</b> is a number that tells the server how often (in seconds) to
|
||||
send 'ping' packets to the client to keep the connection open, to defeat
|
||||
timeouts set by proxies. The client will ignore these messages.
|
||||
|
||||
For example, this creates a connection that pings every 15 seconds and is
|
||||
retryable every 10 seconds if the connection is broken:
|
||||
For example, this creates a connection that allows access from any origin, pings
|
||||
every 15 seconds and is retryable every 10 seconds if the connection is broken:
|
||||
|
||||
```js
|
||||
var es = new EventSource(request, response, {ping: 15, retry: 10});
|
||||
var es = new EventSource(request, response, {
|
||||
headers: {'Access-Control-Allow-Origin': '*'},
|
||||
ping: 15,
|
||||
retry: 10
|
||||
});
|
||||
```
|
||||
|
||||
You can send a ping message at any time by calling `es.ping()`. Unlike
|
||||
@@ -256,4 +292,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
@@ -28,17 +28,10 @@ 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) });
|
||||
}
|
||||
};
|
||||
|
||||
runCase(1);
|
||||
};
|
||||
|
||||
|
||||
+3
-2
@@ -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);
|
||||
|
||||
@@ -19,4 +21,3 @@ ws.onmessage = function(event) {
|
||||
ws.onclose = function(event) {
|
||||
console.log('close', event.code, event.reason);
|
||||
};
|
||||
|
||||
|
||||
@@ -18,4 +18,3 @@ backend sockets
|
||||
balance uri depth 2
|
||||
timeout server 120s
|
||||
server socket1 127.0.0.1:7000
|
||||
|
||||
|
||||
+1
-2
@@ -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);
|
||||
@@ -65,4 +65,3 @@ var server = secure
|
||||
server.on('request', requestHandler);
|
||||
server.on('upgrade', upgradeHandler);
|
||||
server.listen(port);
|
||||
|
||||
|
||||
@@ -36,4 +36,3 @@
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -41,4 +41,3 @@
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
var Stream = require('stream').Stream,
|
||||
util = require('util'),
|
||||
driver = require('websocket-driver'),
|
||||
Headers = require('websocket-driver/lib/websocket/driver/headers'),
|
||||
API = require('./websocket/api'),
|
||||
EventTarget = require('./websocket/api/event_target'),
|
||||
Event = require('./websocket/api/event');
|
||||
@@ -18,7 +19,12 @@ var EventSource = function(request, response, options) {
|
||||
this.lastEventId = request.headers['last-event-id'] || '';
|
||||
this.readyState = API.CONNECTING;
|
||||
|
||||
var self = this;
|
||||
var headers = new Headers(),
|
||||
self = this;
|
||||
|
||||
if (options.headers) {
|
||||
for (var key in options.headers) headers.set(key, options.headers[key]);
|
||||
}
|
||||
|
||||
if (!this._stream || !this._stream.writable) return;
|
||||
process.nextTick(function() { self._open() });
|
||||
@@ -30,7 +36,8 @@ var EventSource = function(request, response, options) {
|
||||
'Content-Type: text/event-stream\r\n' +
|
||||
'Cache-Control: no-cache, no-store\r\n' +
|
||||
'Connection: close\r\n' +
|
||||
'\r\n\r\n' +
|
||||
headers.toString() +
|
||||
'\r\n' +
|
||||
'retry: ' + Math.floor(this._retry * 1000) + '\r\n\r\n';
|
||||
|
||||
this._write(handshake);
|
||||
@@ -122,4 +129,3 @@ for (var method in instance) EventSource.prototype[method] = instance[method];
|
||||
for (var key in EventTarget) EventSource.prototype[key] = EventTarget[key];
|
||||
|
||||
module.exports = EventSource;
|
||||
|
||||
|
||||
+8
-14
@@ -9,10 +9,10 @@ var util = require('util'),
|
||||
API = require('./websocket/api');
|
||||
|
||||
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});
|
||||
options = options || {};
|
||||
|
||||
this._stream = socket;
|
||||
this._driver = driver.http(request, {maxLength: options.maxLength, protocols: protocols});
|
||||
|
||||
var self = this;
|
||||
if (!this._stream || !this._stream.writable) return;
|
||||
@@ -20,17 +20,12 @@ var WebSocket = function(request, socket, body, protocols, options) {
|
||||
var catchup = function() { self._stream.removeListener('data', catchup) };
|
||||
this._stream.on('data', catchup);
|
||||
|
||||
this._stream.setTimeout(0);
|
||||
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);
|
||||
|
||||
@@ -43,4 +38,3 @@ WebSocket.Client = require('./websocket/client');
|
||||
WebSocket.EventSource = require('./eventsource');
|
||||
|
||||
module.exports = WebSocket;
|
||||
|
||||
|
||||
@@ -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 = '';
|
||||
@@ -14,6 +23,20 @@ var API = function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
this._stream.setTimeout(0);
|
||||
this._stream.setNoDelay(true);
|
||||
|
||||
['close', 'end'].forEach(function(event) {
|
||||
this._stream.on(event, function() { self._finalize('', 1006) });
|
||||
}, this);
|
||||
|
||||
this._stream.on('error', function(error) {
|
||||
var event = new Event('error', {message: 'Network error: ' + self.url + ': ' + error.message});
|
||||
event.initEvent('error', false, false);
|
||||
self.dispatchEvent(event);
|
||||
self._finalize('', 1006);
|
||||
});
|
||||
|
||||
this._driver.on('open', function(e) { self._open() });
|
||||
this._driver.on('message', function(e) { self._receiveMessage(e.data) });
|
||||
this._driver.on('close', function(e) { self._finalize(e.reason, e.code) });
|
||||
@@ -75,7 +98,7 @@ var instance = {
|
||||
},
|
||||
|
||||
close: function() {
|
||||
if (this.readyState === API.OPEN) this.readyState = API.CLOSING;
|
||||
if (this.readyState !== API.CLOSED) this.readyState = API.CLOSING;
|
||||
this._driver.close();
|
||||
},
|
||||
|
||||
@@ -120,4 +143,3 @@ for (var method in instance) API.prototype[method] = instance[method];
|
||||
for (var key in EventTarget) API.prototype[key] = EventTarget[key];
|
||||
|
||||
module.exports = API;
|
||||
|
||||
|
||||
@@ -18,4 +18,3 @@ Event.AT_TARGET = 2;
|
||||
Event.BUBBLING_PHASE = 3;
|
||||
|
||||
module.exports = Event;
|
||||
|
||||
|
||||
@@ -26,4 +26,3 @@ var EventTarget = {
|
||||
};
|
||||
|
||||
module.exports = EventTarget;
|
||||
|
||||
|
||||
@@ -2,39 +2,39 @@ var util = require('util'),
|
||||
net = require('net'),
|
||||
tls = require('tls'),
|
||||
driver = require('websocket-driver'),
|
||||
API = require('./api');
|
||||
API = require('./api'),
|
||||
Event = require('./api/event');
|
||||
|
||||
var Client = function(url, protocols, options) {
|
||||
options = 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});
|
||||
this._driver = driver.client(url, {maxLength: options.maxLength, 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.ca) tlsOptions.ca = options.ca;
|
||||
|
||||
var connection = secure
|
||||
? tls.connect(this._uri.port || 443, this._uri.hostname, tlsOptions, onConnect)
|
||||
: net.createConnection(this._uri.port || 80, this._uri.hostname);
|
||||
|
||||
this._stream = connection;
|
||||
this._stream.setTimeout(0);
|
||||
this._stream.setNoDelay(true);
|
||||
|
||||
if (!secure) this._stream.on('connect', onConnect);
|
||||
|
||||
API.call(this);
|
||||
|
||||
['error', 'end'].forEach(function(event) {
|
||||
this._stream.on(event, function() { self._finalize('', 1006) });
|
||||
}, this);
|
||||
API.call(this, options);
|
||||
};
|
||||
util.inherits(Client, API);
|
||||
|
||||
module.exports = Client;
|
||||
|
||||
|
||||
+9
-15
@@ -3,25 +3,19 @@
|
||||
, "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.7.3"
|
||||
, "engines" : {"node": ">=0.4.0"}
|
||||
, "main" : "./lib/faye/websocket"
|
||||
, "dependencies" : {"websocket-driver": ""}
|
||||
, "devDependencies" : {"jsclass": "", "pace": ""}
|
||||
, "dependencies" : {"websocket-driver": ">=0.3.6"}
|
||||
, "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"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
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)
|
||||
this._port = port
|
||||
setTimeout(callback, 100)
|
||||
process.nextTick(callback)
|
||||
},
|
||||
|
||||
stop: function(callback) {
|
||||
this._adapter.stop()
|
||||
setTimeout(callback, 100)
|
||||
process.nextTick(callback)
|
||||
},
|
||||
|
||||
open_socket: function(url, protocols, callback) {
|
||||
@@ -24,12 +26,29 @@ 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) }
|
||||
},
|
||||
|
||||
open_socket_and_close_it_fast: function(url, protocols, callback) {
|
||||
var self = this
|
||||
|
||||
this._ws = new Client(url, protocols, {
|
||||
ca: fs.readFileSync(__dirname + '/../../server.crt')
|
||||
})
|
||||
|
||||
this._ws.onopen = function() { self._open = self._ever_opened = true }
|
||||
this._ws.onclose = function() { self._open = false }
|
||||
|
||||
this._ws.close()
|
||||
|
||||
callback()
|
||||
},
|
||||
|
||||
close_socket: function(callback) {
|
||||
var self = this
|
||||
this._ws.onclose = function() {
|
||||
@@ -49,20 +68,41 @@ JS.ENV.WebSocketSteps = JS.Test.asyncSteps({
|
||||
callback()
|
||||
},
|
||||
|
||||
check_never_opened: function(callback) {
|
||||
this.assert( !this._ever_opened )
|
||||
callback()
|
||||
},
|
||||
|
||||
check_readable: function(callback) {
|
||||
this.assert( this._ws.readable )
|
||||
callback()
|
||||
},
|
||||
|
||||
check_not_readable: function(callback) {
|
||||
this.assert( ! this._ws.readable )
|
||||
callback()
|
||||
},
|
||||
|
||||
check_protocol: function(protocol, callback) {
|
||||
this.assertEqual( protocol, this._ws.protocol )
|
||||
callback()
|
||||
},
|
||||
|
||||
listen_for_message: function(callback) {
|
||||
var self = this
|
||||
var time = new Date().getTime(), self = this
|
||||
this._ws.addEventListener('message', function(message) { self._message = message.data })
|
||||
callback()
|
||||
var timer = setInterval(function() {
|
||||
if (self._message || new Date().getTime() - time > 3000) {
|
||||
clearInterval(timer)
|
||||
callback()
|
||||
}
|
||||
}, 100)
|
||||
},
|
||||
|
||||
send_message: function(message, callback) {
|
||||
this._ws.send(message)
|
||||
setTimeout(callback, 100)
|
||||
var ws = this._ws
|
||||
setTimeout(function() { ws.send(message) }, 500)
|
||||
process.nextTick(callback)
|
||||
},
|
||||
|
||||
check_response: function(message, callback) {
|
||||
@@ -73,11 +113,15 @@ JS.ENV.WebSocketSteps = JS.Test.asyncSteps({
|
||||
check_no_response: function(callback) {
|
||||
this.assert( !this._message )
|
||||
callback()
|
||||
},
|
||||
|
||||
wait: function (ms, callback) {
|
||||
setTimeout(callback, ms)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
JS.ENV.ClientSpec = JS.Test.describe("Client", function() { with(this) {
|
||||
test.describe("Client", function() { with(this) {
|
||||
include(WebSocketSteps)
|
||||
|
||||
before(function() {
|
||||
@@ -96,8 +140,10 @@ JS.ENV.ClientSpec = JS.Test.describe("Client", function() { with(this) {
|
||||
|
||||
it("can close the connection", function() { with(this) {
|
||||
open_socket(socket_url, protocols)
|
||||
check_readable()
|
||||
close_socket()
|
||||
check_closed()
|
||||
check_not_readable()
|
||||
}})
|
||||
|
||||
describe("in the OPEN state", function() { with(this) {
|
||||
@@ -106,26 +152,26 @@ JS.ENV.ClientSpec = JS.Test.describe("Client", function() { with(this) {
|
||||
}})
|
||||
|
||||
it("can send and receive messages", function() { with(this) {
|
||||
listen_for_message()
|
||||
send_message("I expect this to be echoed")
|
||||
listen_for_message()
|
||||
check_response("I expect this to be echoed")
|
||||
}})
|
||||
|
||||
it("sends numbers as strings", function() { with(this) {
|
||||
listen_for_message()
|
||||
send_message(13)
|
||||
listen_for_message()
|
||||
check_response("13")
|
||||
}})
|
||||
|
||||
it("sends booleans as strings", function() { with(this) {
|
||||
listen_for_message()
|
||||
send_message(false)
|
||||
listen_for_message()
|
||||
check_response("false")
|
||||
}})
|
||||
|
||||
it("sends arrays as strings", function() { with(this) {
|
||||
listen_for_message()
|
||||
send_message([13,14,15])
|
||||
listen_for_message()
|
||||
check_response("13,14,15")
|
||||
}})
|
||||
}})
|
||||
@@ -137,11 +183,19 @@ JS.ENV.ClientSpec = JS.Test.describe("Client", function() { with(this) {
|
||||
}})
|
||||
|
||||
it("cannot send and receive messages", function() { with(this) {
|
||||
listen_for_message()
|
||||
send_message("I expect this to be echoed")
|
||||
listen_for_message()
|
||||
check_no_response()
|
||||
}})
|
||||
}})
|
||||
|
||||
it("can be closed before connecting", function() { with(this) {
|
||||
open_socket_and_close_it_fast(socket_url, protocols)
|
||||
wait(10)
|
||||
check_closed()
|
||||
check_never_opened()
|
||||
check_not_readable()
|
||||
}})
|
||||
}})
|
||||
|
||||
describe("with a plain-text server", function() { with(this) {
|
||||
@@ -168,4 +222,3 @@ JS.ENV.ClientSpec = JS.Test.describe("Client", function() { with(this) {
|
||||
behavesLike("socket client")
|
||||
}})
|
||||
}})
|
||||
|
||||
|
||||
+4
-9
@@ -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,4 @@ 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
@@ -1,15 +1,14 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICZTCCAc4CCQDxyrJZrFA0vjANBgkqhkiG9w0BAQUFADB3MQswCQYDVQQGEwJV
|
||||
SzEPMA0GA1UECBMGTG9uZG9uMQ8wDQYDVQQHEwZMb25kb24xDTALBgNVBAoTBEZh
|
||||
eWUxFTATBgNVBAMTDEphbWVzIENvZ2xhbjEgMB4GCSqGSIb3DQEJARYRamNvZ2xh
|
||||
bkBnbWFpbC5jb20wHhcNMTEwODMwMTIzOTM2WhcNMTIwODI5MTIzOTM2WjB3MQsw
|
||||
CQYDVQQGEwJVSzEPMA0GA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MWgTYuXf39XRf2VqicLWqs0xIAc
|
||||
RKBE1VouLM0sbNzMv1yNG7im0bMywXNlOlOmUhtjYZvEx5I10UiJrVxIpEnNiCuZ
|
||||
dgCuB944l/lQrndkaqWtAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEA1UmNwUA7KVaU
|
||||
jg3iofsr0UgFCNO9sZ6PeEoh6NETrckhYd1TB3S7QAgHMiu4e8cEVnlYyIm6oJnp
|
||||
l5edfaUHh3PGwt5jLzpg/l+OVT5qkixRJdazx+pd/CFYIgot2+7hEao9NC4GV1Tl
|
||||
yR0IxlKRsQO3iZlpe7/Klqjaq/r9tQM=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
+13
-13
@@ -1,15 +1,15 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICXAIBAAKBgQDA41OXwCu371AmSGB3Blw2Q/5vW2Pgf1HMBnKMJNITEBmDZSyq
|
||||
6Yiu8VwZmaQ2+q/J/uy/3qQXkrpm0SJuEw83jR4bkBmCyHhkMuyTS6Dwa+hsbm47
|
||||
iYSjjgZwqnLqUQixhu2cOaC+FL7WVR+pC/V548qJEEG8cXqFfQ6rajmhxwIDAQAB
|
||||
AoGABlk1DiCQD8y7mZb2PdSiwlJ4lFewsNnf6lQn/v7TPzdfb5ir4LAxBHkDLACH
|
||||
jBuyH3bZefMs+W2l3u5xMKhF7uJqYcUlJdH2UwRfNG54Hn4SGAjQOK3ONer99sUf
|
||||
USlsWSX1HjAAFMCBwUfKxMZA3VNQfYKTPdm0jSVf85kHO1ECQQD3s6ksm3QpfD0L
|
||||
eG9EoDrqmwnEfpKoWPpz1O0i5tY9VcmhmLwS5Zpd7lB1qjTqzZk4RygU73T/BseJ
|
||||
azehIHK5AkEAx1mSXt+ec8RfzVi/io6oqi2vOcACXRbOG4NQmqUWPnumdwsJjsjR
|
||||
RzEoDFC2lu6448p9sgEq+CkbmgVeiyp4fwJAQnmgySve/NMuvslPcyddKGD7OhSN
|
||||
30ghz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Ms+AwFTK76mcMW
|
||||
xysAGnAUv7h6Qx+M6b3He8OcWVMNqMiv8yI/o2PnsvUS
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
Reference in New Issue
Block a user