From 96a9e2c46aad2e2ab61485a1a836df759bc4aa86 Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 16 Jun 2015 17:58:39 +0200 Subject: [PATCH] Added support for flash messages --- lib/defs.js | 5 ++++- lib/session.js | 11 +++++++++++ lib/utils.js | 13 ++++++++----- package.json | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/defs.js b/lib/defs.js index bb7ab48..b34f252 100644 --- a/lib/defs.js +++ b/lib/defs.js @@ -93,7 +93,8 @@ consts = { ISO_2022_JP: 0x0A, EXTENDED_KANJI_JIS: 0x0D, X_0212_1990: 0x0D, - KS_C_5601: 0x0E + KS_C_5601: 0x0E, + FLASH: 0x10 }, NETWORK: { GENERIC: 0x00, @@ -451,6 +452,8 @@ encodings.ASCII = { // GSM 03.38 } }; +encodings.FLASH = encodings.ASCII; + encodings.ASCII.init(); encodings.LATIN1 = { diff --git a/lib/session.js b/lib/session.js index 88b08f6..134c0c1 100644 --- a/lib/session.js +++ b/lib/session.js @@ -341,6 +341,7 @@ function sendReturn(pdu, status, params, closeAfterSend, callback) { * to - international format * message - string * dlr - boolean defaults to false + * flash - boolean defaults to false * @param func callback(err, smsIds, retPduObjs) */ function sendSms(smsOptions, callback) { @@ -354,6 +355,12 @@ function sendSms(smsOptions, callback) { 'short_message': smsOptions.message }; + // Flash messages overrides default data_coding + if (smsOptions.flash) { + log.debug('larvitsmpp: lib/session.js: sendSms() - Flash SMS detected, set data_coding to 0x10!'); + pduObj.params.data_coding = 0x10; + } + // Request DLRs! if (smsOptions.dlr) { pduObj.params.registered_delivery = 0x01; @@ -650,6 +657,10 @@ function session(sock) { 'sendDlr': smsDlr }; + if (pduObj.params.data_coding === 0x10) { + smsObj.flash = true; + } + returnObj.emit('sms', smsObj); }; diff --git a/lib/utils.js b/lib/utils.js index 535288c..583eeb0 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -405,13 +405,16 @@ function objToPdu(obj, callback) { // If param "short_message" exists, encode it and set parameter "data_coding" accordingly if (obj.params.short_message !== undefined && ! Buffer.isBuffer(obj.params.short_message)) { - // Detect encoding - obj.params.data_coding = defs.encodings.detect(obj.params.short_message); - log.silly('larvitsmpp: lib/utils.js: objToPdu() - data_coding "' + obj.params.data_coding + '" detected'); + // Detect encoding if is not set already + if (obj.params.data_coding === undefined) { + obj.params.data_coding = defs.encodings.detect(obj.params.short_message); - // Now set the hex value - obj.params.data_coding = defs.consts.ENCODING[obj.params.data_coding]; + log.silly('larvitsmpp: lib/utils.js: objToPdu() - data_coding "' + obj.params.data_coding + '" detected'); + + // Now set the hex value + obj.params.data_coding = defs.consts.ENCODING[obj.params.data_coding]; + } // Acutally encode the string shortMsg = obj.params.short_message; diff --git a/package.json b/package.json index dbb544a..9021d02 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "url": "https://github.com/larvit/larvitsmpp", "type": "git" }, - "version": "0.1.3", + "version": "0.1.4", "readmeFilename": "README.md", "readme": "larvitsmpp", "bugs": {