Skip to content

Commit

Permalink
Improving connect API using connection url.
Browse files Browse the repository at this point in the history
  • Loading branch information
farhadi committed Jun 26, 2016
1 parent f12e700 commit 679471a
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/smpp.js
@@ -1,6 +1,7 @@
var net = require('net'),
tls = require('tls'),
tls = require('tls'),
util = require('util'),
parse = require('url').parse,
defs = require('./defs'),
PDU = require('./pdu').PDU,
EventEmitter = require('events').EventEmitter;
Expand All @@ -19,9 +20,9 @@ function Session(options) {
} else {
this.port = options.port;
this.host = options.host;
if (options.isTls) {
if (options.tls) {
transport = tls;
}
}
this.socket = transport.connect(this.port, this.host);
this.socket.on('connect', function() {
self.emit('connect');
Expand Down Expand Up @@ -175,11 +176,24 @@ exports.createServer = function() {
return new Server(arguments[0], arguments[1]);
};

exports.connect = exports.createSession = function(host, port, isTls) {
exports.connect = exports.createSession = function(url) {
var options;
if (argumens.length > 1) {
options = {
host: arguments[0],
port: arguments[1]
};
} else if (typeof url == 'string') {
options = parse(url);
options.host = options.slashes ? options.hostname : url;
options.tls = options.protocol == 'ssmpp:';
} else {
options = url;
}
return new Session({
host: host || 'localhost',
port: port || 2775, // Default SMPP port is 2775
isTls: isTls || false
host: options.host || 'localhost',
port: options.port || (options.tls ? 3550 : 2775),
tls: options.tls || false
});
};

Expand Down

0 comments on commit 679471a

Please sign in to comment.