File tree Expand file tree Collapse file tree 3 files changed +23
-19
lines changed Expand file tree Collapse file tree 3 files changed +23
-19
lines changed Original file line number Diff line number Diff line change @@ -245,18 +245,27 @@ Server.prototype.attach = function(srv, opts){
245
245
// set origins verification
246
246
opts . allowRequest = opts . allowRequest || this . checkRequest . bind ( this ) ;
247
247
248
- // initialize engine
249
- debug ( 'creating engine.io instance with opts %j' , opts ) ;
250
- this . eio = engine . attach ( srv , opts ) ;
248
+ var self = this ;
249
+
250
+ var connectPacket = { type : parser . CONNECT , nsp : '/' } ;
251
+ this . encoder . encode ( connectPacket , function ( encodedPacket ) {
252
+ // the CONNECT packet will be merged with Engine.IO handshake,
253
+ // to reduce the number of round trips
254
+ opts . initialPacket = encodedPacket ;
251
255
252
- // attach static file serving
253
- if ( this . _serveClient ) this . attachServe ( srv ) ;
256
+ // initialize engine
257
+ debug ( 'creating engine.io instance with opts %j' , opts ) ;
258
+ self . eio = engine . attach ( srv , opts ) ;
254
259
255
- // Export http server
256
- this . httpServer = srv ;
260
+ // attach static file serving
261
+ if ( self . _serveClient ) self . attachServe ( srv ) ;
257
262
258
- // bind to engine events
259
- this . bind ( this . eio ) ;
263
+ // Export http server
264
+ self . httpServer = srv ;
265
+
266
+ // bind to engine events
267
+ self . bind ( self . eio ) ;
268
+ } ) ;
260
269
261
270
return this ;
262
271
} ;
Original file line number Diff line number Diff line change @@ -290,7 +290,11 @@ Socket.prototype.onconnect = function(){
290
290
debug ( 'socket connected - writing packet' ) ;
291
291
this . nsp . connected [ this . id ] = this ;
292
292
this . join ( this . id ) ;
293
- this . packet ( { type : parser . CONNECT } ) ;
293
+ // the CONNECT packet for the default namespace
294
+ // has already been sent as an `initialPacket`
295
+ if ( this . nsp . name !== '/' ) {
296
+ this . packet ( { type : parser . CONNECT } ) ;
297
+ }
294
298
} ;
295
299
296
300
/**
Original file line number Diff line number Diff line change @@ -87,9 +87,6 @@ describe('socket.io', function(){
87
87
srv . set ( 'authorization' , function ( o , f ) { f ( null , false ) ; } ) ;
88
88
89
89
var socket = client ( httpSrv ) ;
90
- socket . on ( 'connect' , function ( ) {
91
- expect ( ) . fail ( ) ;
92
- } ) ;
93
90
socket . on ( 'error' , function ( err ) {
94
91
expect ( err ) . to . be ( 'Not authorized' ) ;
95
92
done ( ) ;
@@ -2131,9 +2128,6 @@ describe('socket.io', function(){
2131
2128
} ) ;
2132
2129
srv . listen ( function ( ) {
2133
2130
var socket = client ( srv ) ;
2134
- socket . on ( 'connect' , function ( ) {
2135
- done ( new Error ( 'nope' ) ) ;
2136
- } ) ;
2137
2131
socket . on ( 'error' , function ( err ) {
2138
2132
expect ( err ) . to . be ( 'Authentication error' ) ;
2139
2133
done ( ) ;
@@ -2152,9 +2146,6 @@ describe('socket.io', function(){
2152
2146
} ) ;
2153
2147
srv . listen ( function ( ) {
2154
2148
var socket = client ( srv ) ;
2155
- socket . on ( 'connect' , function ( ) {
2156
- done ( new Error ( 'nope' ) ) ;
2157
- } ) ;
2158
2149
socket . on ( 'error' , function ( err ) {
2159
2150
expect ( err ) . to . eql ( { a : 'b' , c : 3 } ) ;
2160
2151
done ( ) ;
You can’t perform that action at this time.
0 commit comments