diff --git a/lib/client.js b/lib/client.js index c6b851f..c95eded 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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; @@ -66,6 +66,7 @@ function StompClient(opts) { if(tlsOpts === true) { tlsOpts = {}; } + clientId = arguments[8]; } else { address = opts.address || opts.host; @@ -80,6 +81,7 @@ function StompClient(opts) { if(tlsOpts === true) { tlsOpts = opts; } + clientId = opts.clientId; } events.EventEmitter.call(this); @@ -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; @@ -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 diff --git a/test/client.test.js b/test/client.test.js index ffa5369..3cf0053 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -68,6 +68,7 @@ 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(); }, @@ -75,7 +76,7 @@ module.exports = testCase({ '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'); @@ -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(); }, @@ -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'); @@ -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(); },