File tree 2 files changed +25
-3
lines changed
2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -92,11 +92,23 @@ Manager.prototype.emitAll = function () {
92
92
Manager . prototype . updateSocketIds = function ( ) {
93
93
for ( var nsp in this . nsps ) {
94
94
if ( has . call ( this . nsps , nsp ) ) {
95
- this . nsps [ nsp ] . id = this . engine . id ;
95
+ this . nsps [ nsp ] . id = this . generateId ( nsp ) ;
96
96
}
97
97
}
98
98
} ;
99
99
100
+ /**
101
+ * generate `socket.id` for the given `nsp`
102
+ *
103
+ * @param {String } nsp
104
+ * @return {String }
105
+ * @api private
106
+ */
107
+
108
+ Manager . prototype . generateId = function ( nsp ) {
109
+ return ( nsp === '/' ? '' : ( nsp + '#' ) ) + this . engine . id ;
110
+ } ;
111
+
100
112
/**
101
113
* Mix in `Emitter`.
102
114
*/
@@ -358,7 +370,7 @@ Manager.prototype.socket = function (nsp, opts) {
358
370
var self = this ;
359
371
socket . on ( 'connecting' , onConnecting ) ;
360
372
socket . on ( 'connect' , function ( ) {
361
- socket . id = self . engine . id ;
373
+ socket . id = self . generateId ( nsp ) ;
362
374
} ) ;
363
375
364
376
if ( this . autoConnect ) {
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ var io = require('../');
4
4
describe ( 'socket' , function ( ) {
5
5
this . timeout ( 70000 ) ;
6
6
7
- it ( 'should have an accessible socket id equal to the engine.io socket id' , function ( done ) {
7
+ it ( 'should have an accessible socket id equal to the server-side socket id (default namespace) ' , function ( done ) {
8
8
var socket = io ( { forceNew : true } ) ;
9
9
socket . on ( 'connect' , function ( ) {
10
10
expect ( socket . id ) . to . be . ok ( ) ;
@@ -14,6 +14,16 @@ describe('socket', function () {
14
14
} ) ;
15
15
} ) ;
16
16
17
+ it ( 'should have an accessible socket id equal to the server-side socket id (custom namespace)' , function ( done ) {
18
+ var socket = io ( '/foo' , { forceNew : true } ) ;
19
+ socket . on ( 'connect' , function ( ) {
20
+ expect ( socket . id ) . to . be . ok ( ) ;
21
+ expect ( socket . id ) . to . eql ( '/foo#' + socket . io . engine . id ) ;
22
+ socket . disconnect ( ) ;
23
+ done ( ) ;
24
+ } ) ;
25
+ } ) ;
26
+
17
27
it ( 'clears socket.id upon disconnection' , function ( done ) {
18
28
var socket = io ( { forceNew : true } ) ;
19
29
socket . on ( 'connect' , function ( ) {
You can’t perform that action at this time.
0 commit comments