Skip to content

Commit

Permalink
fix: handle missing namespace prefix
Browse files Browse the repository at this point in the history
Fixes #77
  • Loading branch information
darrachequesne committed Dec 29, 2020
1 parent c9d2955 commit 03efd37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Emitter.prototype.to = function(room){
*/

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

/**
Expand Down
20 changes: 19 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,25 @@ describe('emitter', function() {
});

a.on('broadcast event', function(payload) {
setTimeout(done, 1000);
setTimeout(() => {
a.disconnect();
b.disconnect();
done();
}, 1000);
});
});

it('should prepend a missing / to the namespace name', (done) => {
const emitter = ioe({ host: 'localhost', port: '6379' });
const nsp = emitter.of('nsp'); // missing "/"
const cli = client(srv, '/nsp', { forceNew: true });
cli.on('connect', () => {
nsp.emit('broadcast event', 'broadacast payload');
});

cli.on('broadcast event', () => {
cli.disconnect();
done();
});
});
});
Expand Down

0 comments on commit 03efd37

Please sign in to comment.