Compare commits

...

4 Commits
2.0.0 ... 2.0.2

Author SHA1 Message Date
Damien Arrachequesne
a10dc8d92d [chore] Release 2.0.2 2017-06-01 14:01:24 +02:00
Damien Arrachequesne
2b216902e1 [fix] Fix timing issues with middleware (#2948)
Using a middleware could previously lead to a connecting client
receiving a connect event from the server before the server triggers
its own connect event.
2017-05-22 13:01:59 +02:00
Damien Arrachequesne
832b8fc6d9 [chore] Release 2.0.1 2017-05-09 01:40:46 +02:00
Damien Arrachequesne
a0056904c1 [fix] Update path of client file (#2934) 2017-05-09 01:36:40 +02:00
6 changed files with 48 additions and 7 deletions

View File

@@ -1,4 +1,14 @@
2.0.2 / 2017-06-01
===================
* [fix] Fix timing issues with middleware (#2948)
2.0.1 / 2017-05-09
===================
* [fix] Update path of client file (#2934)
2.0.0 / 2017-05-09
===================

View File

@@ -109,7 +109,7 @@ Server.prototype.serveClient = function(v){
return require.resolve(file);
};
if (v && !clientSource) {
clientSource = read(resolvePath( 'socket.io-client/dist/socket.io.min.js'), 'utf-8');
clientSource = read(resolvePath( 'socket.io-client/dist/socket.io.js'), 'utf-8');
try {
clientSourceMap = read(resolvePath( 'socket.io-client/dist/socket.io.js.map'), 'utf-8');
} catch(err) {
@@ -323,7 +323,6 @@ Server.prototype.serve = function(req, res){
debug('serve client source');
res.setHeader('Content-Type', 'application/javascript');
res.setHeader('ETag', expectedEtag);
res.setHeader('X-SourceMap', 'socket.io.js.map');
res.writeHead(200);
res.end(clientSource);
};

View File

@@ -99,6 +99,8 @@ Namespace.prototype.initAdapter = function(){
*/
Namespace.prototype.use = function(fn){
debug('removing initial packet');
delete this.server.eio.initialPacket;
this.fns.push(fn);
return this;
};

View File

@@ -297,9 +297,10 @@ Socket.prototype.onconnect = function(){
debug('socket connected - writing packet');
this.nsp.connected[this.id] = this;
this.join(this.id);
// the CONNECT packet for the default namespace
// has already been sent as an `initialPacket`
if (this.nsp.name !== '/') {
var skip = this.nsp.name === '/' && this.nsp.fns.length === 0;
if (skip) {
debug('packet already sent in initial handshake');
} else {
this.packet({ type: parser.CONNECT });
}
};

View File

@@ -1,6 +1,6 @@
{
"name": "socket.io",
"version": "2.0.0",
"version": "2.0.2",
"description": "node.js realtime framework server",
"keywords": [
"realtime",
@@ -28,7 +28,7 @@
"engine.io": "~3.1.0",
"object-assign": "~4.1.1",
"socket.io-adapter": "~1.1.0",
"socket.io-client": "2.0.0",
"socket.io-client": "~2.0.2",
"socket.io-parser": "~3.1.1"
},
"devDependencies": {

View File

@@ -87,6 +87,9 @@ describe('socket.io', function(){
srv.set('authorization', function(o, f) { f(null, false); });
var socket = client(httpSrv);
socket.on('connect', function(){
expect().fail();
});
socket.on('error', function(err) {
expect(err).to.be('Not authorized');
done();
@@ -2145,6 +2148,9 @@ describe('socket.io', function(){
});
srv.listen(function(){
var socket = client(srv);
socket.on('connect', function(){
done(new Error('nope'));
});
socket.on('error', function(err){
expect(err).to.be('Authentication error');
done();
@@ -2163,6 +2169,9 @@ describe('socket.io', function(){
});
srv.listen(function(){
var socket = client(srv);
socket.on('connect', function(){
done(new Error('nope'));
});
socket.on('error', function(err){
expect(err).to.eql({ a: 'b', c: 3 });
done();
@@ -2186,6 +2195,26 @@ describe('socket.io', function(){
});
});
it('should only call connection after (lengthy) fns', function(done){
var srv = http();
var sio = io(srv);
var authenticated = false;
sio.use(function(socket, next){
setTimeout(function () {
authenticated = true;
next();
}, 300);
});
srv.listen(function(){
var socket = client(srv);
socket.on('connect', function(){
expect(authenticated).to.be(true);
done();
});
});
});
it('should be ignored if socket gets closed', function(done){
var srv = http();
var sio = io(srv);