Code polish

This commit is contained in:
David Majdandžić
2023-04-06 21:03:59 +02:00
parent 12896b2a5b
commit 0945fb0363
6 changed files with 32 additions and 33 deletions

View File

@@ -73,7 +73,8 @@ export default class Client extends SmppSession {
super.defaultMultipleJob = job; super.defaultMultipleJob = job;
} }
destroy(): void {} destroy(): void {
}
doConnect(): PersistentPromise { doConnect(): PersistentPromise {
this.connectPromise = new PersistentPromise((resolve, reject) => { this.connectPromise = new PersistentPromise((resolve, reject) => {

View File

@@ -1,7 +1,7 @@
import {PDU} from "./CommonObjects"; import {PDU} from "./CommonObjects";
export default class MessageIdManager { export default class MessageIdManager {
private static messages: {[key: string]: number} = {}; private static messages: { [key: string]: number } = {};
static addMessageId(message: PDU, id: number): void { static addMessageId(message: PDU, id: number): void {
this.messages[this.getMessageHash(message)] = id; this.messages[this.getMessageHash(message)] = id;

View File

@@ -11,13 +11,11 @@ export default class EchoPduProcessor extends Postprocessor {
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> { processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
return new Promise<any>((resolve, reject) => { return new Promise<any>((resolve, reject) => {
if (!!pdu.command && pdu.command === "submit_sm") { if (!!pdu.command && pdu.command === "submit_sm") {
let sentPdu = new smpp.PDU('deliver_sm', { let echoPdu = new smpp.PDU('deliver_sm', {...pdu});
source_addr: pdu.destination_addr, echoPdu.source_addr = pdu.destination_addr;
destination_addr: pdu.source_addr, echoPdu.destination_addr = pdu.source_addr;
short_message: pdu.short_message entity?.doSendPdu(echoPdu, session);
}); resolve(echoPdu);
entity?.doSendPdu(sentPdu, session);
resolve(sentPdu);
} }
}); });
} }

View File

@@ -5,8 +5,8 @@ import Preprocessor from "../Preprocessor";
const smpp = require('smpp'); const smpp = require('smpp');
export default class LongSmsProcessor extends Preprocessor { export default class LongSmsProcessor extends Preprocessor {
private iterator: number = 0;
static readonly maxMessageSizeBits = 1072; static readonly maxMessageSizeBits = 1072;
private iterator: number = 0;
constructor(type: string) { constructor(type: string) {
// An sms can have a maximum length (short_message) of 1120 bits or 140 bytes. // 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); 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<any> { processPdu(session: any, pdu: PDU, entity?: SmppSession | undefined): Promise<any> {
return new Promise<any>((resolve, reject) => { return new Promise<any>((resolve, reject) => {
if (!!pdu.short_message) { 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;
}
} }

View File

@@ -26,10 +26,10 @@ export default class ProcessorManager {
// Try running eb22a43 to find out what's wrong with the previous approach // Try running eb22a43 to find out what's wrong with the previous approach
ProcessorManager.postprocessors = [ ProcessorManager.postprocessors = [
new EnquireLinkReplyProcessor(Center.name), new EnquireLinkReplyProcessor(Center.name),
new EchoPduProcessor(Center.name),
new DeliverSmReplyProcessor(Client.name), new DeliverSmReplyProcessor(Client.name),
new SubmitSmReplyProcessor(Center.name), new SubmitSmReplyProcessor(Center.name),
new BindTranscieverReplyProcessor(Center.name), new BindTranscieverReplyProcessor(Center.name),
new EchoPduProcessor(Center.name),
new DeliveryReceiptProcessor(Center.name) new DeliveryReceiptProcessor(Center.name)
]; ];
ProcessorManager.preprocessors = [ ProcessorManager.preprocessors = [

View File

@@ -50,7 +50,7 @@ async function main() {
main(); main();
// process.on('exit', cleanup); process.on('exit', cleanup);
// process.on('SIGINT', cleanup); process.on('SIGINT', cleanup);
// process.on('SIGUSR1', cleanup); process.on('SIGUSR1', cleanup);
// process.on('SIGUSR2', cleanup); process.on('SIGUSR2', cleanup);