Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/learnboost/master' into fl…
Browse files Browse the repository at this point in the history
…owdock

* refs/remotes/learnboost/master:
  Release 0.9.5
  Added test for polling with connection close.
  Ensure close upon request close.
  Fix disconnection reason being lost for polling transports.
  Ensure that polling transports work with Connection: close
  Log disconnection reason
  Release 0.9.4
  Release 0.9.4
  Release 0.9.4
  Release 0.9.3
  Firefox will try to parse the response from POST requests, causing a syntax error message in the Web Console. Basically an addition to socketio#501
  Fix issue socketio#795
  Add disconnect from namespace test-case for issue socketio#795

Conflicts:
	lib/transports/http.js
	package.json
  • Loading branch information
lautis committed Apr 6, 2012
2 parents ab36dc3 + a4e53a6 commit a64bcc1
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 12 deletions.
20 changes: 20 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@

0.9.5 / 2012-04-05
==================

* Added test for polling and socket close.
* Ensure close upon request close.
* Fix disconnection reason being lost for polling transports.
* Ensure that polling transports work with Connection: close.
* Log disconnection reason.

0.9.4 / 2012-04-01
==================

* Disconnecting from namespace improvement (#795) [DanielBaulig]
* Bumped client with polling reconnection loop (#438)

0.9.3 / 2012-03-28
==================

* Fix "Syntax error" on FF Web Console with XHR Polling [mikito]

0.9.2 / 2012-03-13
==================

Expand Down
4 changes: 3 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ horizontal scalability, automatic JSON encoding/decoding, and more.

## How to Install

npm install socket.io
```bash
npm install socket.io
```

## How to use

Expand Down
2 changes: 1 addition & 1 deletion lib/socket.io.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var client = require('socket.io-client');
* Version.
*/

exports.version = '0.9.2';
exports.version = '0.9.5';

/**
* Supported protocol version.
Expand Down
15 changes: 11 additions & 4 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,19 @@ Socket.prototype.disconnect = function () {
if (!this.disconnected) {
this.log.info('booting client');

if (this.manager.transports[this.id] && this.manager.transports[this.id].open) {
this.manager.transports[this.id].onForcedDisconnect();
if ('' === this.namespace.name) {
if (this.manager.transports[this.id] && this.manager.transports[this.id].open) {
this.manager.transports[this.id].onForcedDisconnect();
} else {
this.manager.onClientDisconnect(this.id);
this.manager.store.publish('disconnect:' + this.id);
}
} else {
this.manager.onClientDisconnect(this.id);
this.manager.store.publish('disconnect:' + this.id);
this.packet({type: 'disconnect'});
this.manager.onLeave(this.id, this.namespace.name);
this.$emit('disconnect', 'booted');
}

}

return this;
Expand Down
2 changes: 1 addition & 1 deletion lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ Transport.prototype.onClose = function () {

Transport.prototype.end = function (reason) {
if (!this.disconnected) {
this.log.info('transport end');
this.log.info('transport end (' + reason + ')');

var local = this.manager.transports[this.id];

Expand Down
16 changes: 14 additions & 2 deletions lib/transports/http-polling.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ HTTPPolling.prototype.__proto__ = HTTPTransport.prototype;

HTTPPolling.prototype.name = 'httppolling';

/**
* Override setHandlers
*
* @api private
*/

HTTPPolling.prototype.setHandlers = function () {
HTTPTransport.prototype.setHandlers.call(this);
this.socket.removeListener('end', this.bound.end);
this.socket.removeListener('close', this.bound.close);
};

/**
* Removes heartbeat timeouts for polling.
*/
Expand Down Expand Up @@ -128,8 +140,8 @@ HTTPPolling.prototype.write = function (data, close) {
* @api private
*/

HTTPPolling.prototype.end = function () {
HTTPPolling.prototype.end = function (reason) {
this.clearPollTimeout();
return HTTPTransport.prototype.end.call(this);
return HTTPTransport.prototype.end.call(this, reason);
};

3 changes: 2 additions & 1 deletion lib/transports/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ HTTPTransport.prototype.handleRequest = function (req) {
var buffer = new Buffer(0)
, res = req.res
, origin = req.headers.origin
, headers = { 'Content-Length': 1 }
, headers = { 'Content-Length': 1, 'Content-Type': 'text/plain; charset=UTF-8' }
, self = this;

function concat(a, b) {
Expand Down Expand Up @@ -77,6 +77,7 @@ HTTPTransport.prototype.handleRequest = function (req) {
// prevent memory leaks for uncompleted requests
req.on('close', function () {
buffer = new Buffer(0);
self.onClose();
});

if (origin) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "socket.io"
, "version": "0.9.2-flowdock1"
, "version": "0.9.5-flowdock"
, "description": "Real-time apps made cross-browser & easy with a WebSocket-like API"
, "homepage": "http://socket.io"
, "keywords": ["websocket", "socket", "realtime", "socket.io", "comet", "ajax"]
Expand All @@ -16,7 +16,7 @@
, "url": "https://github.com/LearnBoost/socket.io.git"
}
, "dependencies": {
"socket.io-client": "0.9.2"
"socket.io-client": "0.9.5"
, "policyfile": "0.0.4"
, "redis": "0.6.7"
, "wtf8": "0.1.1"
Expand Down
41 changes: 41 additions & 0 deletions test/namespace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,46 @@ module.exports = {
}
});
});
},
'disconnecting from namespace only': function (done) {
var cl = client(++ports)
, io = create(cl)
, ws1
, ws2;

io.of('/foo').on('connection', function (socket) {
socket.disconnect();
});

cl.handshake(function (sid) {
ws1 = websocket(cl, sid);
ws1.on('open', function () {
ws1.packet({
type: 'connect'
, endpoint: '/bar'
});
cl.handshake(function (sid) {
ws2 = websocket(cl, sid);
ws2.on('open', function () {
ws2.packet({
type: 'connect'
, endpoint: '/foo'
});
});
ws2.on('message', function (data) {
if ('disconnect' === data.type) {
cl.end();
ws1.finishClose();
ws2.finishClose();
io.server.close();

data.endpoint.should.eql('/foo');

done();
}
});
});
});
});
}
};
34 changes: 34 additions & 0 deletions test/transports.xhr-polling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,40 @@ module.exports = {
});
},

'test that connection close does not mean disconnect': function (done) {
var cl = client(++ports)
, io = create(cl)
, sid
, end
, disconnected = false

io.configure(function () {
io.set('polling duration', .2);
io.set('close timeout', .5);
});

io.sockets.on('connection', function (client) {
end = function () {
cl.end();
console.log('ending');
client.on('disconnect', function () {
disconnected = true;
});
}
});

cl.handshake(function (sid) {
cl.get('/socket.io/{protocol}/xhr-polling/' + sid);
setTimeout(end, 30);
setTimeout(function () {
console.log('finished');
disconnected.should.be.false;
io.server.close();
done();
}, 100);
});
},

'test sending back data': function (done) {
var cl = client(++ports)
, io = create(cl);
Expand Down

0 comments on commit a64bcc1

Please sign in to comment.