Skip to content
This repository was archived by the owner on Nov 28, 2018. It is now read-only.

Add support for client-id header on connect #9

Merged
merged 2 commits into from
Jul 4, 2011
Merged
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
44 changes: 25 additions & 19 deletions lib/stomp.js
Original file line number Diff line number Diff line change
@@ -95,18 +95,18 @@ function _connect(stomp) {
log = stomp.log;

if (stomp.ssl) {
log.debug('Connecting to ' + stomp.host + ':' + stomp.port + ' using SSL');
stomp.socket = tls.connect(stomp.port, stomp.host, stomp.ssl_options, function() {
log.debug('SSL connection complete');
if (!stomp.socket.authorized) {
log.error('SSL is not authorized: '+stomp.socket.authorizationError);
if (stomp.ssl_validate) {
_disconnect(stomp);
return;
}
}
_setupListeners(stomp);
});
log.debug('Connecting to ' + stomp.host + ':' + stomp.port + ' using SSL');
stomp.socket = tls.connect(stomp.port, stomp.host, stomp.ssl_options, function() {
log.debug('SSL connection complete');
if (!stomp.socket.authorized) {
log.error('SSL is not authorized: '+stomp.socket.authorizationError);
if (stomp.ssl_validate) {
_disconnect(stomp);
return;
}
}
_setupListeners(stomp);
});
} else {
log.debug('Connecting to ' + stomp.host + ':' + stomp.port);
stomp.socket = new net.Socket();
@@ -118,12 +118,16 @@ function _connect(stomp) {
function _setupListeners(stomp) {
function _connected() {
log.debug('Connected to socket');
var headers = {};
if (utils.really_defined(stomp.login) &&
utils.really_defined(stomp.passcode)) {
stomp_connect(stomp, {login: stomp.login, passcode: stomp.passcode});
} else {
stomp_connect(stomp);
headers.login = stomp.login;
headers.passcode = stomp.passcode;
}
if (utils.really_defined(stomp["client-id"])) {
headers["client-id"] = stomp["client-id"];
}
stomp_connect(stomp, headers);
}

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

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

socket.on('close', function(error) {
log.debug('disconnected');
if (error)
if (error) {
log.error('Disconnected with error: ' + error);
stomp.emit("disconnected");
}
stomp.emit("disconnected", error);
});

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

Stomp.prototype = new process.EventEmitter();

/**
* Begin connection
* @param {Object} optional headers
*/
Stomp.prototype.connect = function(headers) {
Stomp.prototype.connect = function() {
var self = this;
_connect(self);
};