Skip to content

Commit a70347b

Browse files
committed
Fixed socketio#285
1 parent 1a2c8aa commit a70347b

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

lib/namespace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ SocketNamespace.prototype.__defineGetter__('volatile', function () {
109109
*/
110110

111111
SocketNamespace.prototype.in = function (room) {
112-
this.flags.endpoint = this.name + room;
112+
this.flags.endpoint = this.name + (room ? '/' + room : '');
113113
return this;
114114
};
115115

test/namespace.test.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,15 @@ module.exports = {
173173

174174
cl.handshake(function (sid) {
175175
ws1 = websocket(cl, sid);
176+
176177
ws1.on('open', function() {
177178
ws1.packet({
178179
type: 'connect'
179180
, endpoint: 'a'
180181
});
181182
});
182183

183-
ws1.on('message', function(data) {
184+
ws1.on('message', function (data) {
184185
if (data.type === 'connect') {
185186
++connect;
186187
if (++calls === expected) finish();
@@ -199,13 +200,49 @@ module.exports = {
199200

200201
cl.handshake(function (sid) {
201202
ws2 = websocket(cl, sid);
202-
ws2.on('open', function() {
203+
204+
ws2.on('open', function () {
203205
ws2.packet({
204206
type: 'connect'
205207
, endpoint: 'a'
206208
});
207209
});
208210
})
209211
})
212+
},
213+
214+
'joining rooms inside a namespace': function (done) {
215+
var cl = client(++ports)
216+
, io = create(cl)
217+
, calls = 0
218+
console.log(data)
219+
, ws;
220+
221+
io.of('/foo').on('connection', function (socket) {
222+
socket.join('foo.bar');
223+
this.in('foo.bar').emit('baz', 'pewpew');
224+
});
225+
226+
cl.handshake(function (sid) {
227+
ws = websocket(cl, sid);
228+
229+
ws.on('open', function (){
230+
ws.packet({
231+
type: 'connect'
232+
, endpoint: '/foo'
233+
});
234+
});
235+
236+
ws.on('message', function (data) {
237+
if (data.type === 'event') {
238+
data.name.should.equal('baz');
239+
240+
cl.end();
241+
ws.finishClose();
242+
io.server.close();
243+
done();
244+
}
245+
});
246+
})
210247
}
211248
};

0 commit comments

Comments
 (0)