Generify everything a little
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
import {Center} from "../Center/Center";
|
||||
import {PDU} from "../CommonObjects";
|
||||
import {PduProcessor} from "./PduProcessor";
|
||||
|
||||
export class DebugPduProcessor extends PduProcessor {
|
||||
servesSessionType: string = Center.name;
|
||||
serverSessionType: string = Center.name;
|
||||
|
||||
processPdu(session: any, pdu: any, ...args: any[]): Promise<any> {
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
session.send(pdu.response(), (replyPdu: any) => {
|
||||
resolve(replyPdu);
|
||||
});
|
||||
if (pdu.response) {
|
||||
session.send(pdu.response(), (replyPdu: any) => {
|
||||
resolve(replyPdu);
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,25 @@
|
||||
import {Center} from "../Center/Center";
|
||||
import {PDU} from "../CommonObjects";
|
||||
import {PduProcessor} from "./PduProcessor";
|
||||
|
||||
const smpp = require("smpp");
|
||||
|
||||
export class EchoPduProcessor extends PduProcessor {
|
||||
servesSessionType: string = Center.name;
|
||||
processPdu(session: any, pdu: any, ...args: any[]): Promise<any> {
|
||||
serverSessionType: string = Center.name;
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
let promises = [];
|
||||
let replyPromise = session.send(pdu.response());
|
||||
let sendPromise = session.send(new smpp.PDU('deliver_sm', {
|
||||
source_addr: pdu.destination_addr,
|
||||
destination_addr: pdu.source_addr,
|
||||
short_message: pdu.short_message
|
||||
}));
|
||||
promises.push(replyPromise);
|
||||
promises.push(sendPromise);
|
||||
if (pdu.response) {
|
||||
let replyPromise = session.send(pdu.response());
|
||||
let sendPromise = session.send(new smpp.PDU('deliver_sm', {
|
||||
source_addr: pdu.destination_addr,
|
||||
destination_addr: pdu.source_addr,
|
||||
short_message: pdu.short_message
|
||||
}));
|
||||
promises.push(replyPromise);
|
||||
promises.push(sendPromise);
|
||||
}
|
||||
Promise.all(promises).then((replyPdus: any) => {
|
||||
resolve(replyPdus);
|
||||
}).catch((error: any) => {
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import {PDU} from "../CommonObjects";
|
||||
import Logger from "../Logger";
|
||||
import {SmppSession} from "../SmppSession";
|
||||
import {DebugPduProcessor} from "./DebugPduProcessor";
|
||||
|
||||
export abstract class PduProcessor {
|
||||
static processors: PduProcessor[] = [];
|
||||
abstract readonly servesSessionType: string;
|
||||
abstract readonly serverSessionType: string;
|
||||
readonly name: string = this.constructor.name;
|
||||
readonly logger: Logger = new Logger(`PduProcessor: ${this.name}`);
|
||||
private static logger: Logger = new Logger("PduProcessor");
|
||||
|
||||
static getProcessor(name: string): PduProcessor {
|
||||
this.logger.log1(`Looking for processor with name ${name}...`);
|
||||
let pduProcessor = this.processors.find((processor: any) => processor.name === name);
|
||||
let pduProcessor = this.processors.find((processor: PduProcessor) => processor.name === name);
|
||||
if (pduProcessor) {
|
||||
this.logger.log1(`Found processor with name ${name}`);
|
||||
return pduProcessor;
|
||||
@@ -35,22 +35,22 @@ export abstract class PduProcessor {
|
||||
|
||||
static areCompatible(session: SmppSession, processor: PduProcessor): boolean {
|
||||
this.logger.log1(`Checking compatibility between session ${session.constructor.name}-${session.getId()} and processor ${processor.name}`);
|
||||
return session.constructor.name === processor.servesSessionType;
|
||||
return session.constructor.name === processor.serverSessionType;
|
||||
}
|
||||
|
||||
static addProcessor(processor: any): void {
|
||||
static addProcessor(processor: new () => PduProcessor): void {
|
||||
PduProcessor.processors.push(new processor());
|
||||
}
|
||||
|
||||
static getProcessorsForType(type: string): PduProcessor[] {
|
||||
return this.processors.filter((processor: any) => processor.servesSessionType === type);
|
||||
return this.processors.filter((processor: PduProcessor) => processor.serverSessionType === type);
|
||||
}
|
||||
|
||||
abstract processPdu(session: any, pdu: any, ...args: any[]): Promise<any>;
|
||||
abstract processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any>;
|
||||
|
||||
serialize(): object {
|
||||
return {
|
||||
servesSessionType: this.servesSessionType,
|
||||
servesSessionType: this.serverSessionType,
|
||||
name: this.name
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user