Fix issue with application crashing on long sms without long sms processing enabled
This commit is contained in:
@@ -6,6 +6,7 @@ const smpp = require('smpp');
|
||||
|
||||
export default class LongSmsProcessor extends Preprocessor {
|
||||
private iterator: number = 0;
|
||||
static readonly maxMessageSizeBits = 1072;
|
||||
|
||||
constructor(type: string) {
|
||||
// An sms can have a maximum length (short_message) of 1120 bits or 140 bytes.
|
||||
@@ -31,25 +32,12 @@ export default class LongSmsProcessor extends Preprocessor {
|
||||
processPdu(session: any, pdu: PDU, entity?: SmppSession | undefined): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
if (!!pdu.short_message) {
|
||||
let encoding: number | undefined = pdu.data_coding;
|
||||
if (!encoding) {
|
||||
encoding = 0;
|
||||
}
|
||||
let characterSizeBits: number = 0;
|
||||
switch (encoding) {
|
||||
case 0:
|
||||
case 1:
|
||||
characterSizeBits = 8;
|
||||
break;
|
||||
case 8:
|
||||
characterSizeBits = 16;
|
||||
break;
|
||||
}
|
||||
let characterSizeBits: number = LongSmsProcessor.getCharacterSizeForEncoding(pdu);
|
||||
let maxMessageLength: number = LongSmsProcessor.maxMessageSizeBits / characterSizeBits;
|
||||
if (characterSizeBits) {
|
||||
let splitMessage: string[] = [];
|
||||
let message: string = pdu.short_message;
|
||||
let messageLength: number = message.length;
|
||||
let maxMessageLength: number = 1072 / characterSizeBits;
|
||||
let messageCount: number = Math.ceil(messageLength / maxMessageLength);
|
||||
for (let i = 0; i < messageCount; i++) {
|
||||
splitMessage.push(message.substr(i * maxMessageLength, maxMessageLength));
|
||||
@@ -77,4 +65,22 @@ export default class LongSmsProcessor extends Preprocessor {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static getCharacterSizeForEncoding(pdu: PDU) {
|
||||
let encoding: number | undefined = pdu.data_coding;
|
||||
if (!encoding) {
|
||||
encoding = 0;
|
||||
}
|
||||
let characterSizeBits: number = 0;
|
||||
switch (encoding) {
|
||||
case 0:
|
||||
case 1:
|
||||
characterSizeBits = 8;
|
||||
break;
|
||||
case 8:
|
||||
characterSizeBits = 16;
|
||||
break;
|
||||
}
|
||||
return characterSizeBits;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import Job from "./Job/Job";
|
||||
import Logger from "./Logger";
|
||||
import PduProcessor from "./PDUProcessor/PduProcessor";
|
||||
import Postprocessor from "./PDUProcessor/Postprocessor/Postprocessor";
|
||||
import LongSmsProcessor from "./PDUProcessor/Preprocessor/Client/LongSmsProcessor";
|
||||
import Preprocessor from "./PDUProcessor/Preprocessor/Preprocessor";
|
||||
|
||||
const NanoTimer = require("nanotimer");
|
||||
@@ -114,9 +115,14 @@ export default abstract class SmppSession {
|
||||
|
||||
doSendPdu(pdu: PDU, session: any): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
this.eventEmitter.emit(this.EVENT.ANY_PDU_TX, pdu);
|
||||
let characterSizeBits: number = LongSmsProcessor.getCharacterSizeForEncoding(pdu);
|
||||
let maxMessageLength: number = LongSmsProcessor.maxMessageSizeBits / characterSizeBits;
|
||||
if (!!pdu.short_message && pdu.short_message.length > maxMessageLength) {
|
||||
pdu.short_message = pdu.short_message.substring(0, maxMessageLength);
|
||||
}
|
||||
session.send(pdu, (reply: any) => resolve(reply));
|
||||
})
|
||||
this.eventEmitter.emit(this.EVENT.ANY_PDU_TX, pdu);
|
||||
});
|
||||
}
|
||||
|
||||
sendSingle(job: Job): Promise<object> {
|
||||
|
||||
Reference in New Issue
Block a user