Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var StompFrameCommands = {

function StompClient(opts) {

var address, port, user, pass, protocolVersion, vhost, reconnectOpts, tlsOpts;
var address, port, user, pass, protocolVersion, vhost, reconnectOpts, tlsOpts, clientId;

if(arguments.length !== 1 || typeof opts === 'string') {
address = opts;
Expand All @@ -66,6 +66,7 @@ function StompClient(opts) {
if(tlsOpts === true) {
tlsOpts = {};
}
clientId = arguments[8];
}
else {
address = opts.address || opts.host;
Expand All @@ -80,6 +81,7 @@ function StompClient(opts) {
if(tlsOpts === true) {
tlsOpts = opts;
}
clientId = opts.clientId;
}

events.EventEmitter.call(this);
Expand All @@ -94,6 +96,7 @@ function StompClient(opts) {
this.vhost = vhost || null;
this.reconnectOpts = reconnectOpts || {};
this.tls = tlsOpts;
this.clientId = clientId || null;
this._retryNumber = 0;
this._retryDelay = this.reconnectOpts.delay;
return this;
Expand Down Expand Up @@ -246,6 +249,9 @@ StompClient.prototype.onConnect = function() {
if(this.vhost && this.version === '1.1')
headers.host = this.vhost;

if(this.clientId)
headers['client-id'] = this.clientId;

var frame = new StompFrame({
command: 'CONNECT',
headers: headers
Expand Down
8 changes: 6 additions & 2 deletions test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ module.exports = testCase({
test.equal(stompClient.address, '127.0.0.1');
test.equal(stompClient.port, 61613);
test.equal(stompClient.version, '1.0');
test.equal(stompClient.clientId, null);

test.done();
},

'check StompClient construction from paremeters': function(test) {
var stompClient = new StompClient(
'test.host.net',1234,'uname','pw', '1.1', 'q1.host.net',
{ retries: 10, delay: 1000 });
{ retries: 10, delay: 1000 }, true, 'testclientid');

test.equal(stompClient.user, 'uname');
test.equal(stompClient.pass, 'pw');
Expand All @@ -85,6 +86,7 @@ module.exports = testCase({
test.equal(stompClient.vhost, 'q1.host.net');
test.equal(stompClient.reconnectOpts.retries, 10);
test.equal(stompClient.reconnectOpts.delay, 1000);
test.equal(stompClient.clientId, 'testclientid');

test.done();
},
Expand All @@ -97,7 +99,8 @@ module.exports = testCase({
pass: 'pw',
protocolVersion: '1.1',
vhost: 'q1.host.net',
reconnectOpts: { retries: 10, delay: 1000 }});
reconnectOpts: { retries: 10, delay: 1000 },
clientId: 'testclientid'});

test.equal(stompClient.user, 'uname');
test.equal(stompClient.pass, 'pw');
Expand All @@ -107,6 +110,7 @@ module.exports = testCase({
test.equal(stompClient.vhost, 'q1.host.net');
test.equal(stompClient.reconnectOpts.retries, 10);
test.equal(stompClient.reconnectOpts.delay, 1000);
test.equal(stompClient.clientId, 'testclientid');

test.done();
},
Expand Down