Comparing version 0.4.21 to 0.4.22
@@ -0,1 +1,8 @@ | ||
v0.4.22 - October 3rd, 2012 | ||
===================== | ||
* clear failsafe cleanup timeout once cleanup is called [AndreasMadsen] | ||
* added w3c compatible CloseEvent for onclose / addEventListener("close", ...). [einaros] | ||
* fix the sub protocol header handler [sonnyp] | ||
* fix unhandled exception if socket closes and 'error' is emitted [jmatthewsr-ms] | ||
v0.4.21 - July 14th, 2012 | ||
@@ -2,0 +9,0 @@ ===================== |
@@ -267,3 +267,3 @@ /*! | ||
// fails for whatever reason | ||
setTimeout(cleanupWebsocketResources.bind(this, true), closeTimeout); | ||
this._closeTimer = setTimeout(cleanupWebsocketResources.bind(this, true), closeTimeout); | ||
} | ||
@@ -320,4 +320,2 @@ else if (this.readyState == WebSocket.CONNECTING) { | ||
if (typeof listener === 'function') { | ||
// Special case for messages as we need to wrap the data | ||
// in a MessageEvent object. | ||
if (method === 'message') { | ||
@@ -327,6 +325,13 @@ function onMessage (data) { | ||
} | ||
// store a reference so we can return the origional function again | ||
// store a reference so we can return the original function from the addEventListener hook | ||
onMessage._listener = listener; | ||
this.on(method, onMessage); | ||
} | ||
else if (method === 'close') { | ||
function onClose (code, message) { | ||
listener.call(this, new CloseEvent(code, message)); | ||
} | ||
// store a reference so we can return the original function from the addEventListener hook | ||
onClose._listener = listener; | ||
this.on(method, onClose); | ||
} else { | ||
@@ -349,6 +354,19 @@ this.on(method, listener); | ||
// Currently only the data attribute is implemented. More can be added later if needed. | ||
Object.defineProperty(this, 'data', { writable: false, value: dataArg }); | ||
this.data = dataArg; | ||
} | ||
/** | ||
* W3C CloseEvent | ||
* | ||
* @see http://www.w3.org/TR/html5/comms.html | ||
* @api private | ||
*/ | ||
function CloseEvent(code, reason) { | ||
this.wasClean = (typeof code == 'undefined' || code == 1000); | ||
this.code = code; | ||
this.reason = reason; | ||
} | ||
/** | ||
* Entirely private apis, | ||
@@ -491,2 +509,3 @@ * which may or may not be bound to a sepcific WebSocket instance. | ||
socket.on('close', cleanupWebsocketResources.bind(this)); | ||
socket.on('error', cleanupWebsocketResources.bind(this)); | ||
@@ -605,2 +624,5 @@ // ensure that the upgradeHead is added to the receiver | ||
this.readyState = WebSocket.CLOSED; | ||
clearTimeout(this._closeTimer); | ||
if (this._socket) { | ||
@@ -607,0 +629,0 @@ removeAllListeners(this._socket); |
@@ -196,3 +196,3 @@ /*! | ||
if (typeof protocol != 'undefined') { | ||
headers['Sec-WebSocket-Protocol'] = protocol; | ||
headers.push('Sec-WebSocket-Protocol: ' + protocol); | ||
} | ||
@@ -199,0 +199,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "simple to use, blazing fast and thoroughly tested websocket client, server and console for node.js, up-to-date against RFC-6455", | ||
"version": "0.4.21", | ||
"version": "0.4.22", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -7,3 +7,3 @@ [![Build Status](https://secure.travis-ci.org/einaros/ws.png)](http://travis-ci.org/einaros/ws) | ||
Passes the quite extensible Autobahn test suite. See http://einaros.github.com/ws for the full reports. | ||
Passes the quite extensive Autobahn test suite. See http://einaros.github.com/ws for the full reports. | ||
@@ -10,0 +10,0 @@ Comes with a command line utility, `wscat`, which can either act as a server (--listen), or client (--connect); Use it to debug simple websocket services. |
@@ -1292,2 +1292,34 @@ var assert = require('assert') | ||
it('should receive valid CloseEvent when server closes with code 1000', function(done) { | ||
var wss = new WebSocketServer({port: ++port}, function() { | ||
var ws = new WebSocket('ws://localhost:' + port); | ||
ws.addEventListener('close', function(closeEvent) { | ||
assert.equal(true, closeEvent.wasClean); | ||
assert.equal(1000, closeEvent.code); | ||
ws.terminate(); | ||
wss.close(); | ||
done(); | ||
}); | ||
}); | ||
wss.on('connection', function(client) { | ||
client.close(1000); | ||
}); | ||
}); | ||
it('should receive vaild CloseEvent when server closes with code 1001', function(done) { | ||
var wss = new WebSocketServer({port: ++port}, function() { | ||
var ws = new WebSocket('ws://localhost:' + port); | ||
ws.addEventListener('close', function(closeEvent) { | ||
assert.equal(false, closeEvent.wasClean); | ||
assert.equal(1001, closeEvent.code); | ||
assert.equal('some daft reason', closeEvent.reason); | ||
ws.terminate(); | ||
wss.close(); | ||
done(); | ||
}); | ||
}); | ||
wss.on('connection', function(client) { | ||
client.close(1001, 'some daft reason'); | ||
}); | ||
}); | ||
}); | ||
@@ -1294,0 +1326,0 @@ |
Sorry, the diff of this file is not supported yet
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
233623
5905
1