Comparing version 0.4.5 to 0.4.6
@@ -0,1 +1,8 @@ | ||
v0.4.6 - Feb 9th 2012 | ||
===================== | ||
* Added browser based file upload example. [einaros] | ||
* Added server-to-browser status push example. [einaros] | ||
* Exposed pause() and resume() on WebSocket object, to enable client stream shaping. [einaros] | ||
v0.4.5 - Feb 7th 2012 | ||
@@ -2,0 +9,0 @@ ===================== |
@@ -113,2 +113,13 @@ /*! | ||
/** | ||
* Pause the client stream | ||
* | ||
* @api public | ||
*/ | ||
WebSocket.prototype.pause = function() { | ||
if (this.readyState != WebSocket.OPEN) throw new Error('not opened'); | ||
return this._socket.pause(); | ||
} | ||
/** | ||
* Sends a ping | ||
@@ -144,2 +155,13 @@ * | ||
/** | ||
* Resume the client stream | ||
* | ||
* @api public | ||
*/ | ||
WebSocket.prototype.resume = function() { | ||
if (this.readyState != WebSocket.OPEN) throw new Error('not opened'); | ||
return this._socket.resume(); | ||
} | ||
/** | ||
* Sends a piece of data | ||
@@ -455,3 +477,3 @@ * | ||
// socket cleanup handlers | ||
socket.on('end', function() { | ||
function closeSocket() { | ||
if (self.readyState == WebSocket.CLOSED) return; | ||
@@ -469,17 +491,5 @@ self._readyState = WebSocket.CLOSED; | ||
self.emit('close', self._closeCode || 1000, self._closeMessage || ''); | ||
}); | ||
socket.on('close', function() { | ||
if (self.readyState == WebSocket.CLOSED) return; | ||
self._readyState = WebSocket.CLOSED; | ||
if (self._socket) { | ||
self._socket.removeAllListeners(); | ||
self._socket.end(); | ||
self._socket = null; | ||
} | ||
if (self._sender) { | ||
self._sender.removeAllListeners(); | ||
self._sender = null; | ||
} | ||
self.emit('close', self._closeCode || 1000, self._closeMessage || ''); | ||
}); | ||
} | ||
socket.on('end', closeSocket); | ||
socket.on('close', closeSocket); | ||
@@ -489,3 +499,3 @@ var receiver = new ReceiverClass(); | ||
function firstHandler(data) { | ||
if (upgradeHead != null) { | ||
if (upgradeHead && upgradeHead.length > 0) { | ||
var head = upgradeHead; | ||
@@ -496,3 +506,3 @@ upgradeHead = null; | ||
dataHandler = realHandler; | ||
receiver.add(data); | ||
if (data) receiver.add(data); | ||
} | ||
@@ -508,11 +518,3 @@ // subsequent packets are pushed straight to the receiver | ||
// object yet. | ||
if (upgradeHead && upgradeHead.length > 0) { | ||
process.nextTick(function() { | ||
if (upgradeHead) { | ||
var toSend = upgradeHead; | ||
upgradeHead = null; | ||
receiver.add(toSend); | ||
} | ||
}); | ||
} | ||
process.nextTick(firstHandler); | ||
@@ -519,0 +521,0 @@ // receiver event handlers |
@@ -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.5", | ||
"version": "0.4.6", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
[![Build Status](https://secure.travis-ci.org/einaros/ws.png)](http://travis-ci.org/einaros/ws) | ||
# ws: a node.js websocket library # | ||
@@ -38,3 +38,3 @@ | ||
``` | ||
### Sending binary data ### | ||
@@ -99,4 +99,6 @@ | ||
See the test cases. | ||
For a full example with a browser client communicating with a ws server, see the examples folder. | ||
Otherwise, see the test cases. | ||
### Running the tests ### | ||
@@ -103,0 +105,0 @@ |
@@ -215,2 +215,39 @@ var assert = require('assert') | ||
describe('#pause and #resume', function() { | ||
it('pauses the underlying stream', function(done) { | ||
// this test is sort-of racecondition'y, since an unlikely slow connection | ||
// to localhost can cause the test to succeed even when the stream pausing | ||
// isn't working as intended. that is an extremely unlikely scenario, though | ||
// and an acceptable risk for the test. | ||
var client; | ||
var serverClient; | ||
var openCount = 0; | ||
function onOpen() { | ||
if (++openCount == 2) { | ||
var paused = true; | ||
serverClient.on('message', function() { | ||
paused.should.not.be.ok; | ||
wss.close(); | ||
done(); | ||
}); | ||
serverClient.pause(); | ||
setTimeout(function() { | ||
paused = false; | ||
serverClient.resume(); | ||
}, 200); | ||
client.send('foo'); | ||
} | ||
} | ||
var wss = new WebSocketServer({port: ++port}, function() { | ||
var ws = new WebSocket('ws://localhost:' + port); | ||
serverClient = ws; | ||
serverClient.on('open', onOpen); | ||
}); | ||
wss.on('connection', function(ws) { | ||
client = ws; | ||
onOpen(); | ||
}); | ||
}); | ||
}); | ||
describe('#ping', function() { | ||
@@ -217,0 +254,0 @@ it('before connect should fail', function(done) { |
Sorry, the diff of this file is not supported yet
200277
53
5207
155
4