Skip to content

Commit

Permalink
Removed the need of providing the mode, will be automatically inferre…
Browse files Browse the repository at this point in the history
…d from the socket presence. The mode it's only used for debug purposes but it's an useful feature to have.
  • Loading branch information
rmruano committed Sep 27, 2021
1 parent 44b1fe0 commit 4e1feb2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/smpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var net = require('net'),
PDU = require('./pdu').PDU,
EventEmitter = require('events').EventEmitter;

function Session(mode, options) {
function Session(options) {
EventEmitter.call(this);
this.options = options || {};
var self = this;
Expand All @@ -19,14 +19,16 @@ function Session(mode, options) {
this._callbacks = {};
this._interval = 0;
this._command_length = null;
this._mode = mode;
this._mode = null;
this._id = Math.floor(Math.random() * (999999 - 100000)) + 100000; // random session id
this._prevBytesRead = 0;
if (options.socket) {
// server mode
this._mode = "server";
this.socket = options.socket;
} else {
// client mode
this._mode = "client";
if (options.tls) {
transport = tls;
}
Expand Down Expand Up @@ -242,7 +244,7 @@ function Server(options, listener) {
this.options = options;

transport.Server.call(this, options, function(socket) {
var session = new Session("server", {socket: socket, debug: self.options.debug});
var session = new Session({socket: socket, debug: self.options.debug});
session.debug("client.connected", "client has connected");
session.server = self;
self.sessions.push(session);
Expand Down Expand Up @@ -315,7 +317,7 @@ exports.connect = exports.createSession = function(url, listener) {
options.port = options.port || (options.tls ? 3550 : 2775);
options.debug = options.debug || false;

var session = new Session("client", options);
var session = new Session(options);
if (listener) {
session.on(options.tls ? 'secureConnect' : 'connect', listener);
}
Expand Down

0 comments on commit 4e1feb2

Please sign in to comment.