From 0945fb0363734b46479d80ea5d4565788873f962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Majdand=C5=BEi=C4=87?= Date: Thu, 6 Apr 2023 21:03:59 +0200 Subject: [PATCH 1/2] Code polish --- src/Client/Client.ts | 3 +- src/MessageIdManager.ts | 2 +- .../Postprocessor/Center/EchoPduProcessor.ts | 12 +++--- .../Preprocessor/Client/LongSmsProcessor.ts | 38 +++++++++---------- src/PDUProcessor/ProcessorManager.ts | 2 +- src/main.ts | 8 ++-- 6 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/Client/Client.ts b/src/Client/Client.ts index f03f598..12b0d53 100644 --- a/src/Client/Client.ts +++ b/src/Client/Client.ts @@ -73,7 +73,8 @@ export default class Client extends SmppSession { super.defaultMultipleJob = job; } - destroy(): void {} + destroy(): void { + } doConnect(): PersistentPromise { this.connectPromise = new PersistentPromise((resolve, reject) => { diff --git a/src/MessageIdManager.ts b/src/MessageIdManager.ts index 5796f66..57b8ae7 100644 --- a/src/MessageIdManager.ts +++ b/src/MessageIdManager.ts @@ -1,7 +1,7 @@ import {PDU} from "./CommonObjects"; export default class MessageIdManager { - private static messages: {[key: string]: number} = {}; + private static messages: { [key: string]: number } = {}; static addMessageId(message: PDU, id: number): void { this.messages[this.getMessageHash(message)] = id; diff --git a/src/PDUProcessor/Postprocessor/Center/EchoPduProcessor.ts b/src/PDUProcessor/Postprocessor/Center/EchoPduProcessor.ts index 2821a65..fb1f01a 100644 --- a/src/PDUProcessor/Postprocessor/Center/EchoPduProcessor.ts +++ b/src/PDUProcessor/Postprocessor/Center/EchoPduProcessor.ts @@ -11,13 +11,11 @@ export default class EchoPduProcessor extends Postprocessor { processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise { return new Promise((resolve, reject) => { if (!!pdu.command && pdu.command === "submit_sm") { - let sentPdu = new smpp.PDU('deliver_sm', { - source_addr: pdu.destination_addr, - destination_addr: pdu.source_addr, - short_message: pdu.short_message - }); - entity?.doSendPdu(sentPdu, session); - resolve(sentPdu); + let echoPdu = new smpp.PDU('deliver_sm', {...pdu}); + echoPdu.source_addr = pdu.destination_addr; + echoPdu.destination_addr = pdu.source_addr; + entity?.doSendPdu(echoPdu, session); + resolve(echoPdu); } }); } diff --git a/src/PDUProcessor/Preprocessor/Client/LongSmsProcessor.ts b/src/PDUProcessor/Preprocessor/Client/LongSmsProcessor.ts index 9cae1e7..6886f5b 100644 --- a/src/PDUProcessor/Preprocessor/Client/LongSmsProcessor.ts +++ b/src/PDUProcessor/Preprocessor/Client/LongSmsProcessor.ts @@ -5,8 +5,8 @@ import Preprocessor from "../Preprocessor"; const smpp = require('smpp'); export default class LongSmsProcessor extends Preprocessor { - private iterator: number = 0; static readonly maxMessageSizeBits = 1072; + private iterator: number = 0; constructor(type: string) { // An sms can have a maximum length (short_message) of 1120 bits or 140 bytes. @@ -29,6 +29,24 @@ export default class LongSmsProcessor extends Preprocessor { super(type); } + 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; + } + processPdu(session: any, pdu: PDU, entity?: SmppSession | undefined): Promise { return new Promise((resolve, reject) => { if (!!pdu.short_message) { @@ -65,22 +83,4 @@ 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; - } } \ No newline at end of file diff --git a/src/PDUProcessor/ProcessorManager.ts b/src/PDUProcessor/ProcessorManager.ts index 2454a1b..5b8dcd9 100644 --- a/src/PDUProcessor/ProcessorManager.ts +++ b/src/PDUProcessor/ProcessorManager.ts @@ -26,10 +26,10 @@ export default class ProcessorManager { // Try running eb22a43 to find out what's wrong with the previous approach ProcessorManager.postprocessors = [ new EnquireLinkReplyProcessor(Center.name), - new EchoPduProcessor(Center.name), new DeliverSmReplyProcessor(Client.name), new SubmitSmReplyProcessor(Center.name), new BindTranscieverReplyProcessor(Center.name), + new EchoPduProcessor(Center.name), new DeliveryReceiptProcessor(Center.name) ]; ProcessorManager.preprocessors = [ diff --git a/src/main.ts b/src/main.ts index 109ed7a..74a644f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -50,7 +50,7 @@ async function main() { main(); -// process.on('exit', cleanup); -// process.on('SIGINT', cleanup); -// process.on('SIGUSR1', cleanup); -// process.on('SIGUSR2', cleanup); \ No newline at end of file +process.on('exit', cleanup); +process.on('SIGINT', cleanup); +process.on('SIGUSR1', cleanup); +process.on('SIGUSR2', cleanup); \ No newline at end of file From 5e31372207ed861698f1756a7b0ae21fd9cd196c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Majdand=C5=BEi=C4=87?= Date: Fri, 7 Apr 2023 08:39:58 +0200 Subject: [PATCH 2/2] Clean up the project for building --- .gitignore | 2 ++ .run/main.js.run.xml | 5 ----- .run/main.ts.run.xml | 2 +- package.json | 5 +++-- src/Logger.ts | 5 +---- src/main.ts | 31 ++----------------------------- 6 files changed, 9 insertions(+), 41 deletions(-) delete mode 100644 .run/main.js.run.xml diff --git a/.gitignore b/.gitignore index ef7d308..cecb95a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ package-lock.json sessions.json client_sessions.json center_sessions.json +dist +main.exe diff --git a/.run/main.js.run.xml b/.run/main.js.run.xml deleted file mode 100644 index de16bf6..0000000 --- a/.run/main.js.run.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.run/main.ts.run.xml b/.run/main.ts.run.xml index 1e97700..4f310e5 100644 --- a/.run/main.ts.run.xml +++ b/.run/main.ts.run.xml @@ -2,7 +2,7 @@ - +