Skip to content

Commit 03efd37

Browse files
fix: handle missing namespace prefix
Fixes #77
1 parent c9d2955 commit 03efd37

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Emitter.prototype.to = function(room){
111111
*/
112112

113113
Emitter.prototype.of = function(nsp){
114-
return new Emitter(this.redis, this.prefix, nsp);
114+
return new Emitter(this.redis, this.prefix, (nsp[0] !== "/" ? "/" : "") + nsp);
115115
};
116116

117117
/**

test/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,25 @@ describe('emitter', function() {
106106
});
107107

108108
a.on('broadcast event', function(payload) {
109-
setTimeout(done, 1000);
109+
setTimeout(() => {
110+
a.disconnect();
111+
b.disconnect();
112+
done();
113+
}, 1000);
114+
});
115+
});
116+
117+
it('should prepend a missing / to the namespace name', (done) => {
118+
const emitter = ioe({ host: 'localhost', port: '6379' });
119+
const nsp = emitter.of('nsp'); // missing "/"
120+
const cli = client(srv, '/nsp', { forceNew: true });
121+
cli.on('connect', () => {
122+
nsp.emit('broadcast event', 'broadacast payload');
123+
});
124+
125+
cli.on('broadcast event', () => {
126+
cli.disconnect();
127+
done();
110128
});
111129
});
112130
});

0 commit comments

Comments
 (0)