Permalink
Browse files

[fix] Fixes socket.use error packet (#2772)

* fix(socket): Fixes socket.use error packet which drops nodejs due to nuances of Nodejs' EventEmitter

* fix(socket): Fixes missing error event on socket

* fix(socket): test fix, should listen for clientSocket instead of server socket

* minor update
  • Loading branch information...
1 parent 797c9a3 commit 1e31769062cef627cb47a735d83d623b71d912f5 @serhiisol serhiisol committed with darrachequesne Dec 1, 2016
Showing with 15 additions and 13 deletions.
  1. +1 −1 lib/socket.js
  2. +14 −12 test/socket.io.js
View
@@ -498,7 +498,7 @@ Socket.prototype.dispatch = function(event){
this.run(event, function(err){
process.nextTick(function(){
if (err) {
- return self.emit('error', err.data || err.message);
+ return self.error(err.data || err.message);
}
emit.apply(self, event);
});
View
@@ -2273,9 +2273,14 @@ describe('socket.io', function(){
var sio = io(srv);
srv.listen(function(){
- var socket = client(srv, { multiplex: false });
+ var clientSocket = client(srv, { multiplex: false });
- socket.emit('join', 'woot');
+ clientSocket.emit('join', 'woot');
+
+ clientSocket.on('error', function(err){
+ expect(err).to.be('Authentication error');
+ done();
+ });
sio.on('connection', function(socket){
socket.use(function(event, next){
@@ -2288,10 +2293,6 @@ describe('socket.io', function(){
socket.on('join', function(){
done(new Error('nope'));
});
- socket.on('error', function(err){
- expect(err).to.be('Authentication error');
- done();
- });
});
});
});
@@ -2301,9 +2302,14 @@ describe('socket.io', function(){
var sio = io(srv);
srv.listen(function(){
- var socket = client(srv, { multiplex: false });
+ var clientSocket = client(srv, { multiplex: false });
- socket.emit('join', 'woot');
+ clientSocket.emit('join', 'woot');
+
+ clientSocket.on('error', function(err){
+ expect(err).to.eql({ a: 'b', c: 3 });
+ done();
+ });
sio.on('connection', function(socket){
socket.use(function(event, next){
@@ -2315,10 +2321,6 @@ describe('socket.io', function(){
socket.on('join', function(){
done(new Error('nope'));
});
- socket.on('error', function(err){
- expect(err).to.eql({ a: 'b', c: 3 });
- done();
- });
});
});
});

0 comments on commit 1e31769

Please sign in to comment.