Skip to content

Commit 5fb3059

Browse files
committed
Merge pull request benjaminws#9 from joshuarubin/master
Add support for client-id header on connect
2 parents 5fa19f3 + c260b38 commit 5fb3059

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

lib/stomp.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,18 @@ function _connect(stomp) {
9595
log = stomp.log;
9696

9797
if (stomp.ssl) {
98-
log.debug('Connecting to ' + stomp.host + ':' + stomp.port + ' using SSL');
99-
stomp.socket = tls.connect(stomp.port, stomp.host, stomp.ssl_options, function() {
100-
log.debug('SSL connection complete');
101-
if (!stomp.socket.authorized) {
102-
log.error('SSL is not authorized: '+stomp.socket.authorizationError);
103-
if (stomp.ssl_validate) {
104-
_disconnect(stomp);
105-
return;
106-
}
107-
}
108-
_setupListeners(stomp);
109-
});
98+
log.debug('Connecting to ' + stomp.host + ':' + stomp.port + ' using SSL');
99+
stomp.socket = tls.connect(stomp.port, stomp.host, stomp.ssl_options, function() {
100+
log.debug('SSL connection complete');
101+
if (!stomp.socket.authorized) {
102+
log.error('SSL is not authorized: '+stomp.socket.authorizationError);
103+
if (stomp.ssl_validate) {
104+
_disconnect(stomp);
105+
return;
106+
}
107+
}
108+
_setupListeners(stomp);
109+
});
110110
} else {
111111
log.debug('Connecting to ' + stomp.host + ':' + stomp.port);
112112
stomp.socket = new net.Socket();
@@ -118,12 +118,16 @@ function _connect(stomp) {
118118
function _setupListeners(stomp) {
119119
function _connected() {
120120
log.debug('Connected to socket');
121+
var headers = {};
121122
if (utils.really_defined(stomp.login) &&
122123
utils.really_defined(stomp.passcode)) {
123-
stomp_connect(stomp, {login: stomp.login, passcode: stomp.passcode});
124-
} else {
125-
stomp_connect(stomp);
124+
headers.login = stomp.login;
125+
headers.passcode = stomp.passcode;
126126
}
127+
if (utils.really_defined(stomp["client-id"])) {
128+
headers["client-id"] = stomp["client-id"];
129+
}
130+
stomp_connect(stomp, headers);
127131
}
128132

129133
var socket = stomp.socket;
@@ -154,13 +158,15 @@ function _setupListeners(stomp) {
154158

155159
socket.on('error', function(error) {
156160
log.error(error.stack + 'error name: ' + error.name);
161+
stomp.emit("error", error);
157162
});
158163

159164
socket.on('close', function(error) {
160165
log.debug('disconnected');
161-
if (error)
166+
if (error) {
162167
log.error('Disconnected with error: ' + error);
163-
stomp.emit("disconnected");
168+
}
169+
stomp.emit("disconnected", error);
164170
});
165171

166172
if (stomp.ssl) {
@@ -236,15 +242,15 @@ function Stomp(args) {
236242
this.ssl = args['ssl'] ? true : false;
237243
this.ssl_validate = args['ssl_validate'] ? true : false;
238244
this.ssl_options = args['ssl_options'] || {};
245+
this['client-id'] = args['client-id'] || null;
239246
};
240247

241248
Stomp.prototype = new process.EventEmitter();
242249

243250
/**
244251
* Begin connection
245-
* @param {Object} optional headers
246252
*/
247-
Stomp.prototype.connect = function(headers) {
253+
Stomp.prototype.connect = function() {
248254
var self = this;
249255
_connect(self);
250256
};

0 commit comments

Comments
 (0)