Bumped upstream versions, minor adjustments to docs and a log message

This commit is contained in:
2016-05-16 11:22:30 +02:00
parent f4a7c51b85
commit 5da55e0f52
4 changed files with 110 additions and 102 deletions
+12 -12
View File
@@ -4,20 +4,20 @@
"mocha": true
},
"rules": {
"global-strict": [2, "always"],
"no-mixed-requires": false,
"no-multi-spaces": false,
"space-infix-ops": true,
"strict": [2, "safe"],
"no-mixed-requires": 0,
"no-multi-spaces": 0,
"space-infix-ops": 2,
"quotes": [1, "single"],
"vars-on-top": [1, true],
"one-var": [1, true],
"no-shadow": false,
"eol-last": false,
"key-spacing": false,
"vars-on-top": 1,
"one-var": 1,
"no-shadow": 0,
"eol-last": 0,
"key-spacing": 0,
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
"space-unary-ops": [1, { "words": true, "nonwords": true }],
"no-underscore-dangle": false,
"camelcase": false,
"no-process-exit": false
"no-underscore-dangle": 0,
"camelcase": 0,
"no-process-exit": 0
}
}
+93 -85
View File
@@ -11,59 +11,63 @@ This is a simplified implementation of the SMPP protocol.
This will setup a client that connects to localhost, port 2775 without username or password and send a message.
var larvitsmpp = require('larvitsmpp');
```javascript
var larvitsmpp = require('larvitsmpp');
larvitsmpp.client(function(err, clientSession) {
clientSession.sendSms({
'from': '46701113311',
'to': '46709771337',
'message': 'Hello world'
});
larvitsmpp.client(function(err, clientSession) {
clientSession.sendSms({
'from': '46701113311',
'to': '46709771337',
'message': 'Hello world'
});
// Gracefully close connection
clientSession.unbind();
});
// Gracefully close connection
clientSession.unbind();
});
```
### Some connection parameters and DLR
This will setup a client that connects to given host, port with username and password, send a password and retrieve a DLR.
larvitsmpp.client({
'host': 'smpp.somewhere.com',
'port': 2775,
'username': 'foo',
'password': 'bar'
}, function(err, clientSession) {
if (err) {
throw err;
}
```javascript
larvitsmpp.client({
'host': 'smpp.somewhere.com',
'port': 2775,
'username': 'foo',
'password': 'bar'
}, function(err, clientSession) {
if (err) {
throw err;
}
clientSession.sendSms({
'from': '46701113311',
'to': '46709771337',
'message': '«baff»',
'dlr': true
}, function(err, smsId, retPduObj) {
if (err) {
throw err;
}
clientSession.sendSms({
'from': '46701113311',
'to': '46709771337',
'message': '«baff»',
'dlr': true
}, function(err, smsId, retPduObj) {
if (err) {
throw err;
}
console.log('SMS sent, smsId(s): ' + smsId.join(', '));
console.log('Return PDU object:');
console.log(retPduObj);
});
console.log('SMS sent, smsId(s): ' + smsId.join(', '));
console.log('Return PDU object:');
console.log(retPduObj);
});
clientSession.on('dlr', function(dlr, dlrPduObj) {
console.log('DLR received:');
console.log(dlr);
clientSession.on('dlr', function(dlr, dlrPduObj) {
console.log('DLR received:');
console.log(dlr);
console.log('DLR PDU object:');
console.log(dlrPduObj);
console.log('DLR PDU object:');
console.log(dlrPduObj);
// Gracefully close connection
clientSession.unbind();
});
});
// Gracefully close connection
clientSession.unbind();
});
});
```
## Server
@@ -71,64 +75,68 @@ This will setup a client that connects to given host, port with username and pas
This will setup a password less server on localhost, port 2775 and console.log() incomming commands.
var larvitsmpp = require('larvitsmpp');
```javascript
var larvitsmpp = require('larvitsmpp');
larvitsmpp.server(function(err, serverSession) {
if (err) {
throw err;
}
larvitsmpp.server(function(err, serverSession) {
if (err) {
throw err;
}
serverSession.on('data', function(data) {
console.log('command: ' + data.command);
});
});
serverSession.on('data', function(data) {
console.log('command: ' + data.command);
});
});
```
### With auth, returning smsId and DLR
Example code below:
// This should of course be replaced with your preferred auth system
function checkuserpass(username, password, callback) {
if (username === 'foo' && password === 'bar') {
// The last parameter is just user meta data that will be attached to the session as "userData" and is optional
callback(null, true, {'username': 'foo', 'userId': 123});
} else {
callback(null, false);
}
}
```javascript
// This should of course be replaced with your preferred auth system
function checkuserpass(username, password, callback) {
if (username === 'foo' && password === 'bar') {
// The last parameter is just user meta data that will be attached to the session as "userData" and is optional
callback(null, true, {'username': 'foo', 'userId': 123});
} else {
callback(null, false);
}
}
larvitsmpp.server({
'checkuserpass': checkuserpass
}, function(err, serverSession) {
if (err) {
throw err;
}
larvitsmpp.server({
'checkuserpass': checkuserpass
}, function(err, serverSession) {
if (err) {
throw err;
}
// Incoming SMS!
serverSession.on('sms', function(sms) {
// Incoming SMS!
serverSession.on('sms', function(sms) {
// It is important to run the sms.resp() since this is a part of the protocol
sms.resp({
// It is important to run the sms.resp() since this is a part of the protocol
sms.resp({
// Decimal value status code
// Default is 0 == no error
// See SMPP spec for all available status codes
// For example: 11 == 0000000B == ESME_RINVDSTADR == "Invalid destination address".
'status': 0,
// Decimal value status code
// Default is 0 == no error
// See SMPP spec for all available status codes
// For example: 11 == 0000000B == ESME_RINVDSTADR == "Invalid destination address".
'status': 0,
// Set SMS id, this is important if DLR is to be connected with the right SMS but is not mandatory
'smsId': 450
});
// Set SMS id, this is important if DLR is to be connected with the right SMS but is not mandatory
'smsId': 450
});
// Oh, the sms sender wants a dlr (delivery report), send it!
if (sms.dlr === true) {
serverSession.sendDlr(sms);
// Oh, the sms sender wants a dlr (delivery report), send it!
if (sms.dlr === true) {
serverSession.sendDlr(sms);
// To send a negative delivery report do:
//serverSession.sendDlr(sms, false);
}
});
});
// To send a negative delivery report do:
//serverSession.sendDlr(sms, false);
}
});
});
```
## Session Events
+1 -1
View File
@@ -198,7 +198,7 @@ function send(pdu, closeAfterSend, callback) {
}
} else {
err = new Error('Event triggered but incoming PDU is not a response or seqNr does not match. isResp: ' + incPduObj.isResp().toString() + ' incSeqNr: ' + incPduObj.seqNr + ' expected seqNr: ' + pduObj.seqNr);
log.warn(err.message);
log.warn('larvitsmpp: lib/session.js: send() - this.on(incomingPduObj) - ' + err.message);
callback(err);
}
});
+4 -4
View File
@@ -9,16 +9,16 @@
"dependencies": {
"async": "^1.5.2",
"iconv-lite": "^0.4.13",
"moment": "^2.11.2",
"moment": "^2.13.0",
"utils-merge": "^1.0.0",
"winston": "^2.1.1"
"winston": "^2.2.0"
},
"description": "Simplified SMPP implementation",
"devDependencies": {
"coveralls": "^2.11.9",
"istanbul": "^0.4.3",
"mocha": "^2.4.5",
"portfinder": "^0.4.0"
"portfinder": "^1.0.3"
},
"keywords": [
"smpp",
@@ -31,7 +31,7 @@
"url": "https://github.com/larvit/larvitsmpp",
"type": "git"
},
"version": "0.1.18",
"version": "0.1.19",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/larvit/larvitsmpp/issues"