File tree Expand file tree Collapse file tree 2 files changed +52
-4
lines changed
Expand file tree Collapse file tree 2 files changed +52
-4
lines changed Original file line number Diff line number Diff line change @@ -291,12 +291,19 @@ Socket.prototype.disconnect = function () {
291291 if ( ! this . disconnected ) {
292292 this . log . info ( 'booting client' ) ;
293293
294- if ( this . manager . transports [ this . id ] && this . manager . transports [ this . id ] . open ) {
295- this . manager . transports [ this . id ] . onForcedDisconnect ( ) ;
294+ if ( '' === this . namespace . name ) {
295+ if ( this . manager . transports [ this . id ] && this . manager . transports [ this . id ] . open ) {
296+ this . manager . transports [ this . id ] . onForcedDisconnect ( ) ;
297+ } else {
298+ this . manager . onClientDisconnect ( this . id ) ;
299+ this . manager . store . publish ( 'disconnect:' + this . id ) ;
300+ }
296301 } else {
297- this . manager . onClientDisconnect ( this . id ) ;
298- this . manager . store . publish ( 'disconnect:' + this . id ) ;
302+ this . packet ( { type : 'disconnect' } ) ;
303+ this . manager . onLeave ( this . id , this . namespace . name ) ;
304+ this . $emit ( 'disconnect' , 'booted' ) ;
299305 }
306+
300307 }
301308
302309 return this ;
Original file line number Diff line number Diff line change @@ -282,5 +282,46 @@ module.exports = {
282282 }
283283 } ) ;
284284 } ) ;
285+ } ,
286+ 'disconnecting from namespace only' : function ( done ) {
287+ var cl = client ( ++ ports )
288+ , io = create ( cl )
289+ , ws1
290+ , ws2 ;
291+
292+ io . of ( '/foo' ) . on ( 'connection' , function ( socket ) {
293+ socket . disconnect ( ) ;
294+ } ) ;
295+
296+ cl . handshake ( function ( sid ) {
297+ ws1 = websocket ( cl , sid ) ;
298+ ws1 . on ( 'open' , function ( ) {
299+ ws1 . packet ( {
300+ type : 'connect'
301+ , endpoint : '/bar'
302+ } ) ;
303+ cl . handshake ( function ( sid ) {
304+ ws2 = websocket ( cl , sid ) ;
305+ ws2 . on ( 'open' , function ( ) {
306+ ws2 . packet ( {
307+ type : 'connect'
308+ , endpoint : '/foo'
309+ } ) ;
310+ } ) ;
311+ ws2 . on ( 'message' , function ( data ) {
312+ if ( 'disconnect' === data . type ) {
313+ cl . end ( ) ;
314+ ws1 . finishClose ( ) ;
315+ ws2 . finishClose ( ) ;
316+ io . server . close ( ) ;
317+
318+ data . endpoint . should . eql ( '/foo' ) ;
319+
320+ done ( ) ;
321+ }
322+ } ) ;
323+ } ) ;
324+ } ) ;
325+ } ) ;
285326 }
286327} ;
You can’t perform that action at this time.
0 commit comments