Refactor processors to reduce duplicate code
This commit is contained in:
@@ -2,17 +2,15 @@ import SmppSession from "../../../SmppSession";
|
||||
import Preprocessor from "../Preprocessor";
|
||||
|
||||
export default class DeliveryReceiptRequestProcessor extends Preprocessor {
|
||||
private iterator: number = 0;
|
||||
applicableCommands: string[] = ['submit_sm'];
|
||||
|
||||
constructor(type: string) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||
protected doProcess(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
if (!!pdu.command && pdu.command === "submit_sm") {
|
||||
pdu.registered_delivery = 1;
|
||||
}
|
||||
pdu.registered_delivery = 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ import SmppSession from "../../../SmppSession";
|
||||
import Preprocessor from "../Preprocessor";
|
||||
|
||||
export default class DestinationEnumeratorProcessor extends Preprocessor {
|
||||
applicableCommands: string[] = ['submit_sm', 'deliver_sm'];
|
||||
private iterator: number = 0;
|
||||
|
||||
constructor(type: string) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||
protected doProcess(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
if (!!pdu.destination_addr) {
|
||||
pdu.destination_addr = pdu.destination_addr + this.padLeft(String(this.iterator++), '0', 5);
|
||||
@@ -19,4 +20,4 @@ export default class DestinationEnumeratorProcessor extends Preprocessor {
|
||||
private padLeft(str: string, pad: string, length: number): string {
|
||||
return (new Array(length + 1).join(pad) + str).slice(-length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import Preprocessor from "../Preprocessor";
|
||||
const smpp = require('smpp');
|
||||
|
||||
export default class LongSmsProcessor extends Preprocessor {
|
||||
applicableCommands: string[] = ['submit_sm', 'deliver_sm'];
|
||||
static readonly maxMessageSizeBits = 1072;
|
||||
private iterator: number = 0;
|
||||
|
||||
@@ -47,7 +48,7 @@ export default class LongSmsProcessor extends Preprocessor {
|
||||
return characterSizeBits;
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: PDU, entity?: SmppSession | undefined): Promise<any> {
|
||||
protected doProcess(session: any, pdu: PDU, entity?: SmppSession | undefined): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
if (!!pdu.short_message) {
|
||||
let characterSizeBits: number = LongSmsProcessor.getCharacterSizeForEncoding(pdu);
|
||||
@@ -83,4 +84,4 @@ export default class LongSmsProcessor extends Preprocessor {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ import SmppSession from "../../../SmppSession";
|
||||
import Preprocessor from "../Preprocessor";
|
||||
|
||||
export default class SourceEnumeratorProcessor extends Preprocessor {
|
||||
applicableCommands: string[] = ['submit_sm', 'deliver_sm'];
|
||||
private iterator: number = 0;
|
||||
|
||||
constructor(type: string) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||
protected doProcess(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
if (!!pdu.source_addr) {
|
||||
pdu.source_addr = pdu.source_addr + this.padLeft(String(this.iterator++), '0', 5);
|
||||
@@ -19,4 +20,4 @@ export default class SourceEnumeratorProcessor extends Preprocessor {
|
||||
private padLeft(str: string, pad: string, length: number): string {
|
||||
return (new Array(length + 1).join(pad) + str).slice(-length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user